-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: modulepreload polyfill #4058
feat: modulepreload polyfill #4058
Conversation
I don't see a reason for always executing the polyfill, even for browsers that support But we already have support detection for const relList = document.createElement('link').relList
const supportsModulePreload = relList && relList.supports && relList.supports('modulepreload') I added a guard to the polyfill so we don't change things for chromium where this is already supported. |
We discussed with the team that this feature is going to be merged before the beta for the next minor (2.5) |
Co-authored-by: Shinigami <chrissi92@hotmail.de>
@patak-js ist it possible to also to check polyfillModulePreload where skip const is defined e.g. |
@croban could you raise a bug report with a reproduction if you found a problem? AFAICS the polyfill plugin is not included in
|
Did this never make it into 2.4.0 or later? I am currently running vite 2.6.7 and I see the modulepreload-polyfill script getting loaded in firefox, but I am also seeing some files downloaded twice in Firefox. Interestingly, the modulepreload-polyfill is being loaded using rel=modulepreload and is one of the files being downloaded twice. |
Would you open an issue with a reproduction so we can better track this? |
Description
Implement
rel="modulepreload"
polyfill as described in https://guybedford.com/es-module-preloading-integrity as proposed by @yyx990803I had to modify importAnalysisBuild to always use 'modulepreload' if config.build.polyfillModulePreload is enabled, instead of the runtime detection
About naming, I used Used
config.build.polyfillModulePreload
and idvite:modulepreload-polyfill
Another option could be to use
config.build.polyfillModulepreload
and for the idvite:module-preload-polyfill
IIUC when modulepreload is supported (as in chrome), the polyfill will still issue a fetch. I trust Guy Beford here that this isn't a problem.
The polyfill was adapted from https://github.com/guybedford/es-module-shims/blob/main/src/es-module-shims.js, removing the import maps logic that was intervened with this polyfill (leaving almost the same version as in the blog post)
Tested in Firefox and seems to be fetching the scripts correctly, more testing would be good.
Additional Notes
We could wait after the beta is out to merge this one, or we could use the beta to test it so it is already part of 2.4.0
What is the purpose of this pull request?