-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Nuxt 3 prefetch all assets from every pages and every layouts. #13778
Comments
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Same here ... |
I have a reproduce here: https://stackblitz.com/edit/github-krh2ru?file=layouts%2Fadmin-layout.vue I don't really understand why this is a minor bug when it's almost impossible to use the layouts and components are sharing styles. |
@engvie I would advise against using global styles in any case, particularly ones targeted at elements like |
@danielroe I agree they should be scoped. Maybe there is a better solution for what I am trying to do. In my admin layout I want to import |
I think this is not the same problem @engvie. My point is that app after building and deploying prefetch for example all the images from all the pages and all the layouts. So when I deploy my Landing Page with 0 images it prefetches all the images from the rest of the pages. And it critically lengthens the LCP metric. But I agree it is not minor because it makes deploying an app with lots of pages and lots of images pointless :) I've got like 20 sec of LCP on my page when the other metrics are great. Finally we workaround it by temporarily removing videos on the page and we are waiting for the fix to come. |
@kstraszewski I have 2 layout files:
Both styles are included at both layouts. The admin style are destroying the default layout style. I don't know if there is another way to separate the styles? I think this is an issue? |
Ok so I think this is part of this issue. It would be great to have layout css scoped to all the pages that are child of that layout, but I didn't test adding This style part of that bug is not bothering me much, coz css doesn't weight lots of kb, but imgs and videos are. |
Has someone already identified what causes this problem ? |
We're facing the same issue #14093. On production, it mets our server's rate limit so some last assets couldn't be loaded (403 Forbidden) |
@danielroe the idea of writing styles in scoped / css modules is great. However, the problem affects all the Assets, which makes it problematic to deploy large applications. For example, the size of downloaded assets on one of my pages in Nuxt2 is ~700kb, when in Nuxt Bridge it reaches ~3mb on the same page. P.S. The bug is also reproduced in Nuxt Bridge + webpack. |
@danielroe is there any workaround for this bug? I'm migrating my projects to Nuxt 3. The size of every page is great, we are getting 2x smaller bundler compared with nuxt2. But this bug is killing FCP and LCP on the larger project. I found a workaround for images, you can put images to public and then Nuxt doesn't load them at all, but I can't find a workaround for the rest of the pages (js + CSS) and unfortunately nuxt loads all of them. Using new Performance Insight devtool tool for chrome it shows that when I go to PageA (for example: https://b2c.qa2.lendi.pl/ for debug) FCP is loaded after nuxt prefetch all of js and CSS from the other pages (for example, prefetch js and CSS from this page https://b2c.qa2.lendi.pl/kredyty-hipoteczne which is under development, but unfortunately burdens rest of the production pages :/ ) For my opinion (correct me if I'm wrong) Nuxt3 lacks Smart prefetching from Nuxt2 is this feature planned for a stable release or rather its matter of 3.1 version? @edit: https://www.lendi.pl/kredyty-hipoteczne/ The current version linked above (https://b2c.qa2.lendi.pl/kredyty-hipoteczne) is under development, and written in Nuxt3. We achieved a 3.5x smaller bundle 700kb vs 2.5mb, but exactly the same https://pagespeed.web.dev/ performance score, coz huge FCP and LCP. I know I can go with CLS to 0 and polish some things, but with this FCP and LCP I can't achieve good perf :/ |
I think the error lies in And The bundle renderer tries to prefetched 1. [assets of However, IMO. The fix about this could either be
Edit: It seems the manifest itself is also incorrect. The entry somehow contains all image assets of all routes as dependency while page themselves contains none. |
Thanks for the helpful summary @mmis1000. There is a PR open that does not prefetch prefetches of dynamic dependencies: nuxt-contrib/vue-bundle-renderer#30. You are also right that the manifest is incorrect; this seems to be an issue with vite or the vite config within nuxt that we'll need to resolve as well. |
After a bit of inspection, the image module are actually bundled alongside the entry point. So the manifest is technically correct. So the actual question is: |
I think I located the reason that cause urls to be bundled into entry chunk. It's caused by Insert a return under this line https://github.com/nuxt/framework/blob/e38de4af4dd98705a226b551fa9d6729d7b1a130/packages/vite/src/plugins/dynamic-base.ts#L69 makes nuxt generate proper manifest instead of a broken one. By the way, the generated script from that plugin seems to be also incorrect. It missed a I wonder if you rewrite the one that import the asset instead of rewrite asset chunk itself, would this still happen? Cause that, |
Made a patch set to experiment idea above, and it do work (on my machine). https://gist.github.com/mmis1000/3a5882636a340df8e67b84099a9364ad Paste here for who interested. |
@danielroe I see that this problem has been known for several months.
|
There is a difference between preload and prefetch. There is an issue awaiting review that prevents over-zealous prefetching: nuxt-contrib/vue-bundle-renderer#30. There is another issue which is that the vite manifest that is built includes too many assets as direct dependencies of the entry point. Yes, this is planned to be resolved. Likely we need to merge nuxt/framework#5398 first. |
We can't wait to see this fixed sooner! Fingers crossed! |
Yea I still have this issue also, but it will be allowed in the future: |
Any update ? |
@mirash333 when an issue is closed, it usually won't receive any updates. Feel free to follow along #18376 |
@mirash333 Are you still having issues? I opened this bug. #22817 |
Production is a real challenge for me. Why is it necessary to thoroughly scan all assets, and why can't we make updates directly in the production environment? Why does even a minor change to a single image require a full rebuild? |
Idk if it can help, but if you are using
However, with
|
This comment was marked as off-topic.
This comment was marked as off-topic.
I would like to know if this is possible in Nuxt 3 : router: { |
I have the same issue with nuxt bridge and vite. env
|
@hamedniroumand I have the same problem. Did you get a solution? |
@jschroeter You can use the |
nuxt3,nuxt.config.ts.Just have a try,It is work for me. hooks: { |
Yes, that works, thanks. But I have the feeling it would be better if the Nuxt prefetching behavior would be adjustable from e.g. inside the template. E.g. look at this example: https://stackblitz.com/edit/nuxt-starter-qw2rgq?file=app.vue
which results in
In this example it doesn't make sense that the PNG image and both videos are prefetched. |
Environment
Nuxt CLI v3.0.0-rc.0
Nuxt project info:
Darwin
v16.14.0
3.0.0-rc.0
[email protected]
vite
css
-
-
Reproduction
https://github.com/kstraszewski/nuxt3-playground/tree/prefetching-all-assets
Also we have qa version of our project here:
https://b2c.qa2.lendi.pl/design
Describe the bug
Nuxt after build prefetch all the assets like CSS, fonts, media, imgs from all the pages and all the layouts. As you can see in the repo example you have
/pageA
which implementlayout-a
, with some video in the pageA.vue. Also, you have/pageB
which implementslayout-b
which loads popular @mdi/font.The problem I have is it doesn't matter on which page you go nuxt always loads all the assets. When you go to
/pageA
you will see the mdi fonts from pageB and layoutB also are prefetching by the nuxt:PageA:
PageB:
Both pages Loads a lot.
My guess is that vite builder prefetch every URL that he find in CSS or template.
Additional context
It makes nuxt unusable in production mode because It hurts LCP very badly:
As you can see on the example below we have huge LCP (I've made some tricks witch mdi/fonts, but this is very ugly solution) with fully loaded mdi/fonts I've received 27 sec of LCP.
https://pagespeed.web.dev/report?url=https%3A%2F%2Fb2c.qa2.lendi.pl%2Fdesign
Logs
No response
The text was updated successfully, but these errors were encountered: