Link Prefetching: also prefetch `pageContext`
Currently, there's no way to do any user-defined additional preloading jobs after finishing to preload static assets. So it's impossible to prefetch data needed for routes. Having an onAfterPreload hook (tried to match the naming convention) will solve the problem and it'll be very helpful to deeply tune the page performance.
My idea so far for this is to:
- Extend the
prefetchLinkoption, e.g.:useClientRouter({ prefetchLinks: { prefetchPageContext: { when: 'HOVER', expire: 5 * 1000 // The prefetched `pageContext` is considered fersh for 5 seconds }, prefetchSaticAssets: { when: 'VIEWPORT' } } }) - Allow the definition of a client-side-only
onBeforeRender()(needed for tools such as Relay).
I agree with you, that sounds very simple and straightforward.
With 0.4 the DX is quite straightforward:
// /renderer/_default.page.client.js
export const prefetchStaticAssets = { when: 'VIEWPORT' }
export const prefetchPageContext = { when: 'HOVER', expire: 10 * 1000 }
Implementation should be fairly easy.
Hi @brillout, is this part of the v1 design (#578) and being worked on? I'd love to work on it!
@archit-p It isn't but this feature can be implemented independently of the V1 design. PR welcome!
Hi, @brillout! May I work on it?
Hi @usk94, yes!
@brillout Let me ask a question. Should prefetchPageContext.when default to false? Also, do I need to support override for individual links?
So far I'm inclined to think that we can enable it on HOVER by default. But let's see.
Also, do I need to support override for individual links?
I think that would be nice? Or do you see an issue with that?
@brillout
OK, I'll implement HOVER as default for now🙆♂️
Or do you see an issue with that?
I don't have at the moment. I just asked to be sure, thank you!