-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Option to disable modulepreload #5120
Comments
Re-tested it with Chrome 95 because it announced they changed some heuristic on the preload directive, but the behavious is still the same. |
I'm currently having to run a transform on top of the generated HTML to strip out the preload tags for the exact same reason above. It's not limited to JS either, it's preloading SVG's etc. As @jpvincent says, I think a config option to simply disable the behaviour would be a welcome addition. |
Hi @spacedawwwg : are you striping out the HTML outside of Vite or is it an option I'm not aware of ? |
Outside of vite - I have a few transform scripts I run to do 'extras' I've not figured in vite yet |
Here are more statistics, on a global level this time : https://almanac.httparchive.org/en/2021/resource-hints#correlation-with-core-web-vitals Please really consider being able to turn off preload of JS in Vite. |
@jpvincent do you know the historical rationale why |
Tracked down the generation of vite/packages/vite/src/node/plugins/html.ts Line 479 in 46b862a
|
For understandting the issue more deeply, here is a historical Google Chrome article on |
Here is my writeup how to transform generated HTML in SvelteKit hooks using cheetah. By changing |
No, I dont have any rationale, my guess being that the team chose this because it is said to be a good practice. But here we need more nuance, as this default does not work for everyone. |
The time between the first I'm surprised there's 50 JS files being loaded. That 20ms would likely be smaller if there were fewer files. I would generally expect things not to be so granularly chunked, but it's hard to advise on that without access to the source. There's some weird stuff in these files. E.g. it looks like https://www.radiofrance.fr/client/chunks/index-83a12101.js includes the
As does https://www.radiofrance.fr/client/chunks/index-3715f060.js:
You'd probably get just as big of a win by not including that stuff. I'm also wondering why I also see Microsoft copyright notices and am not sure they really need to be included?
And then there's fun stuff like https://api.privacy-center.org/v1/locations/current?fields[]=country_code&fields[]=region_code which takes over 300ms to load a very tiny response of I'm not sure an option to disable preloading would really be worth the added complexity especially when there's lower hanging fruit... |
Is the complexity of this issue of:
If you are open to new patches I am happy to get it done, but if the discussion is going to be stalled whether the issue is real or not, then it is going to be much more nuanced conversation. |
We should properly justify adding each new option. Your list isn't complete. The cost of a new feature isn't the time it will take to add it, but the added complexity to the code base and how it will interact later with other features that will impact the long-term maintenance of the project. |
This one reminded me of an old issue from vite1 days modulepreload requiring a polyfill in most non-chromium browsers makes it a less than ideal candidate imho. If script type module are correctly defered like the spec suggests that would be a clean alternative, no? |
We need to disable it as well, but for different reasons. Our project is enormous and preloading every single module like this is not warranted. |
hi @benmccann . That's HTTP/2 at play here : the 20 ms you are talking about is the moment Chrome is queuing the file (white color). Before that, there is a 100ms of wait. Take a look at the darker green color : that is the actual transit on the network. Delaying CSS delays First Paint, but on Chrome it also delays the start of the download of the images, because they chose to wait for the layout information before starting getting them. |
@benmccann : thank you for taking a look at what's inside the JS files or about the latency on the server. The frontend is based on SvelteKit. |
I'm afraid I have no idea what I'm supposed to be looking at in the link you posted. Is it possible to use Chrome screenshots instead of webpagetest.org screenshots to discuss this?
I don't see that at all or am unsure what you're referring to. I just went to https://radiofrance.fr/ now. The JS started downloading at 830.35ms The CSS started downloading at 854.03ms That's a difference of less than 25ms.
So you're also suggesting the network is being saturated? That's a different claim than the one made before that CSS files don't start downloading until later. That's easier for me to believe, but there's been no clear evidence of that shared here.
You can't just swap one for another.
We try to have best practices enabled by default, as few options as possible, and clear explanations of what options do and when to change them. When considering whether to add a new option it must be clear that it's helpful, that it shouldn't just be made the default for all cases, and if it is to be added then there needs to be clear documentation regarding the tradeoffs of setting it. |
I found an issue in SvelteKit affecting the download order while investigating this: sveltejs/kit@d138efe Can we consider this issue as solved now? |
I figured out how to disable it, you have to remove __vitePreload( ) in the index.js file. To be safe, I'm doing it dynamically using an IIS managed handler that replaces all javascript files on the fly with the following:
and all html files on the fly with the following:
I also set the cache-control header with max-age and immutable, such as this:
and now my importmap is working, everything is caching properly, and both methods that vite uses to preload are gone. |
It should only be considered resolved when there is way to properly disable both preload features. |
In theory it's fixing the original problem I had : First Paint being delayed by JS preloads in Chrome. |
As mentioned earlier, a justification would need to be provided for adding a new option. Happy to consider, but we would need a detailed explanation of why it's required.
It might be better to file a new issue if this is the desired reason. Almost all the discussion here is about @jpvincent's issue, which is quite different. Please don't assume prior knowledge of importmaps when discussing since it's a new feature I haven't seen before
As a heads up, a new version of SvelteKit with the patch was released a few hours ago
Another alternative in this scenario would be to add a preload for the main image appearing higher in the document |
Closing as @sapphi-red pointed out this issue is a duplicate of #5991, we can keep discussing there |
Clear and concise description of the problem
Hi
The current version of Chrome is pretty aggressive with the
preload
andmodulepreload
directive : it will download the JS first, then get the CSS files. Because CSS files are blocking page rendering, thepreload
directive will delay rendering.You can use webpagetest to see the effect
The vertical green bar is the moment the page is displayed. Chrome rushes on the preloaded JS files first
then request the CSS files
In this test, it needs an additional few hundred milliseconds after the last blocking CSS file to calculate the page layout and displays it. If the JS files were not preloaded, the CSS would be downloaded sooner, and so the page first paint. We use SSR, so the first paint is good enough for the user to see and we can allow the user to see the page without JS for a few seconds.
Safari iOS and Firefox behave less aggressively and will just get the CSS first and the rest later.
Suggested solution
I would need to deactivate manually the
modulepreload
on the JS files, at least as long as Chrome has this behaviour.Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: