-
-
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
Non-modern build should also ("pre")load CSS #9902
Comments
Hello Tal500. I appreciate your effort put in here. I was trying out your solution on our code, but the production build was failing due to this: Is this issue in any way related? |
Hello! Are you talking about the SvelteKit legacy PR I made? If so, you better comment this issue on the PR I sent on SvelteKit, not here.(was it a mistake?) Anyway, for your case, can you:
Please comment to me to this on the PR in SvelteKit, for a better discussion. |
Update: After working on PR #9920, I've changed my opinion - I think that on legacy builds we should have full preloading support. |
After some investigation, I realized that Vite always inline the legacy CSS in injected HTML code. But why? @yyx990803 , what is the reason for 940d483 ? Wouldn't it be nicer to also load the CSS normally, the same way you load it in modern browsers? (any technical difference between modern and legacy here in CSS?) |
It's described here. #2062 (comment) |
Thank you for the reference! So as far as I see, there is no principle from Vite maintainers for not preloading content on legacy, right? My PR #9920 does exactly this. If we want preloading on legacy, we can get rid of all the CSS inlining mess (update: this PR got rid of it). Did I get it right? Do you agree we shall do it? |
IIUC Vite inlines CSS to realize preloading CSS by using JS chunks instead. webpack-contrib/mini-css-extract-plugin#294 |
OK, I read the sources, so now I understand the "XHR request" meaning on #2062 (comment) . So I will simply make such a request on legacy, and it will just "embed" the content of the CSS file between Sounds good? |
I think that works for most cases but it won't for a CSS file containing relative paths ( I'm not sure but an approach like https://guybedford.com/es-module-preloading-integrity might work. |
How about do (in parallel):
Do you think that the browser will execute the query twice? It seems that the caching should be immediate, but I'm not sure. Or to calculate correctly how to get the correct path. We can also "give up" on the detection of error in CSS path on legacy, and then use the trick of loading to image and then to link. |
I had updated PR #9920 to do this things. vite/packages/vite/src/node/plugins/importAnalysisBuild.ts Lines 58 to 169 in e72c090
|
Any update here? |
Description
While I'm doing my efforts in sveltejs/kit#6265 to add legacy support to SvelteKit on the Vite way, I had noticed that when navigating from one page to the other, the internal function
__vitePreload
is called, which is defined in the pluginimportAnalysisBuild
.As far as I understand, the purpose of this function is to preload JS modules and also to (pre?)load CSS files.
On legacy output chunks, it shuts down the preloading ability.
I understand that there is no need to preload JS modules on non-modern(i.e. non ESModule compatible) browsers, but for the correct way of loading CSS, the CSS files should(?) be loaded in
__vitePreload
.According to my local tests, if the CSS are getting preloaded on legacy builds, everything works great in my legacy work on SvelteKit.
Suggested solution
Change the code of the plugin
importAnalysisBuild
to (pre?)load CSS anyway, and when the browser is also modern, import also the preloaded JS files.Alternative
You tell me?
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: