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
Opt-in / opt-out of module preloading #5991
Comments
currently, i suffer from this default config. |
Hi However I can do a follow-up after we stopped using What went better :
It comes at a cost : the whole JS application executes later. You can guess it from the screenshot above by taking a look at the player button in the footer. That was confirmed with figures coming from our real users after one week into production : here are the values for the First Contentful Paint going down on some pages we monitor, as seen from the Chrome Report User eXperience and reported from our chrome users to Google Search. So, if you are not using SSR correctly, not developing the progressive enhancement way or are doing a real SPA that fully relies on JS, the default |
For anyone interested, until this is resolved within Vite itself. This is how I strip the module preloads (and image preloads) from my HTML AFTER a Vite build has run. NOTE: I am using vite-plugin-ssr, though the below is a good starter.
|
cool, would be nice if that's going to be a config for each chunk or a global config for all files. |
@AlonMiz @jpvincent @spacedawwwg @AlexandreBonaventure would you check if your use cases would be covered by the feature as implemented in: |
Clear and concise description of the problem
Hey there!
Recently came across a problem where we need to load some mocks or test files conditionally, like this:
This is all well and good but vite is injecting
modulepreload
links for those. Generally speaking this is a good default behaviour, however in this case I would really like to opt-out of preloading because:I know this issue (#5120) is asking for a somewhat similar request but I think the 2 proposal are valid and different:
The above ticket needs to disable the feature altogether, whereas this ticket is more about having the ability to filter which files can be preloaded.
One can argue that the import should be stripped anyways
and that
if (USE_INTEROP_MOCK)
should beif (import.meta.USE_INTEROP_MOCK)
but we actually sometimes need this code in production to enable debug mode capabilities (like a feature-flag)Suggested solution
Couple of ideas:
Mark async depdencies as modulepreload #2835 (comment)
This suggest using an api like
import.meta.preload()
to opt-in for preloadingSupport comment directive like
import('/interop/mock/index' /*@vite-preload-ignore*/);
Maybe a config ? I am not a big fan of this one...
like
build.preloadExclude: glob
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: