Use modulepreload to speculatively prefetch #182
Closed
GrandSchtroumpf
started this conversation in
Proposals For Qwik
Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
|
thank you @GrandSchtroumpf ! as work has already begun on this before this proposal, I'll create the proper RFC issue (#193) and close this proposal We're going to work on getting the buffering story right once and for all in the upcoming weeks, we would love to collaborate on this like the last time. Thanks again! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
What is it about?
Use to prefetch modules
What's the motivation for this proposal?
Problems you are trying to solve:
We cannot use the Cache API to prefetch module in devmode which leads to poor performance
Goals you are trying to achieve:
Separate the speculative prefetch process from the caching process.
Any other context or information you want to share:
modulepreloadhas been discussed and discarded in the early day of qwik because Firefox didn't support it. This is not the case anymore.prefetchStrategy->linkRel: 'modulepreload', but it only prefetch initial modules, those known at build time.modulepreloadcould increase FCP/LCP. It was decided to change Qwik doc prefetch strategy to accumulate real user data to see if this is the case.If
modulepreloadaffect negatively FCP/LCP it's still possible to useprefetchStrategy->linkInsert: 'js-append'instead of'html-append'to delay to initial prefetch.Proposed Solution / Feature
What do you propose?
Separate Speculative Prefetch from Caching
Speculative Prefetch (should work in dev mode) :
Use
<link rel="modulepreload" />to prefetch the modules:modulepreloadin the head (similar tolinkInsert: 'html-append'prefetchStrategy)DOMContentLoadedto start listening onqprefetcheventqprefetchevent, append new<link rel="modulepreload" />tags with the bundle href. If modulepreload is not support just do a regularfetchfor the Service Worker to hook it.Caching (should work only in prod mode) :
DOMContentLoadedregister service worker, send all existingmodulepreloadhrefs to the service worker to cache.fetchcache the response if it's a qwik moduleCode examples
This is a working code snippet. To use it
entry.ssrsetprefetchStrategy:root.tsxremove<PrefetchServiceWorker />&<PrefetchGraph />and adduseModulePrelaod()(see code snippet)sw.jsin thepublicfolder (see code snippet)useModulePreload.tsxsw.jsLinks / References
MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/modulepreload
Experiment: https://github.com/thejackshelton/sw-playground
app using
useModulePreload: https://qwik-playground.vercel.app/ (github: https://github.com/GrandSchtroumpf/qwik-hueeye)Beta Was this translation helpful? Give feedback.
All reactions