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
Disable prefetch
for dynamic imports
#18376
Comments
Have you maybe tried preloading these components? I think by default async components are prefetched by you should be able to manually oreload them |
Had a similar problem some months ago. With ALL Font-Awesome Icons including all premium styles etc. the build process never finished. It barely managed to (took 10+ minutes afaik instead of the usual 1~2) with just two sets active. |
prefetch
for dynamic imports
What do you mean by "workaround available"? |
It is possible to remove dynamic import prefetching in the nuxt.hook('build:manifest', (manifest) => {
for (const key in manifest) {
// or other logic
manifest[key].dynamicImports = []
}
}) |
I zeroed manifest.dynamicImports, but it didn't solve problem with preload. |
In that case, this is triggered directly by vite's preloading behaviour. If you can provide a reproduction, I can investigate further. Note: some situations (but likely not the original reported issue here) might be somewhat ameliorated by #19008 which will be included in v3.2.1. |
I did a super hacky workaround because i couldnt find a better solution: added the following nitro plugin at
Looking forward to remove this workaround when a fix is found, the main problem i had was that all images loaded via |
Link for open issue: nuxt/nuxt#18376
This method does not work on nuxt 3.2.2 |
Link for open issue: nuxt/nuxt#18376
@Pysdbi I have the version "nuxt": "^ 3.1.1" . I tried what you suggest and it doesn't work. |
Nothing from above doesn't really helps. Setting I was even trying to set it directly as vite extend config like this:
but result is the same. |
Looks like in my case, the problem was related to So adding |
In my case, the issue was that every image was being prefetched. All versions of an image used on img/picture srcset's were prefetched, and there was a weird behavior where Chrome was always prioritizing and waiting for the highest pixel density version. That obviously was slowing down my initial page load. Inspired by @danielroe's workaround, I made my own that disables prefetch for image assets: nuxt.hook('build:manifest', (manifest) => {
const keysToRemove = []
for (const key in manifest) {
const file = manifest[key]
if (file.assets) {
file.assets = file.assets
.filter(
(asset: string) =>
!asset.endsWith('.webp') &&
!asset.endsWith('.jpg') &&
!asset.endsWith('.png')
)
}
}
}) The result was a 300ms faster initial page load and lot less images being transfered unnecessarily in my case, so I'm sharing this workaround here so that anybody can use it. |
I'm getting the same kind of problems when auto-importing SVG icons from a directory using This only occurs on 3.4.2 and forcing nuxt version 3.4.1 doesn't exhibit this behavior. Reproduction here: https://stackblitz.com/edit/github-2upgzp |
@Dreckr where should I put this code in my Nuxt application ? |
Thank you so much @Dreckr! |
I put the workaround in the nuxt.config.ts file.
|
Anyone have a workaround for the client? From what I can gather most of these workarounds only affect the server/TTFB. Unless Im wrong? |
any updates ?! |
1 similar comment
any updates ?! |
How to completely disable prefetch? This has a significant impact on website performance, especially in mobile device scoring. |
I am also having this problem. it prefetches the swiper bundle from another page other than the page i am visiting and i get a bad rating on pagespeed |
@JieJieeee Stay tuned for further updates on this topic here |
This is still not working, in 2024 there still isn't a Nuxt 3 way to stop preloading / prefetching. |
@danielroe Any updates? |
any updates regarding prefetching of components? |
I did it like this: export default defineNuxtConfig(() => {
hooks: {
'build:manifest'(manifest) {
for (const key in manifest) {
const file = manifest[key];
if (file.prefetch) {
file.prefetch = false;
}
// Prevents inclusion of <link rel="stylesheet" /> during SSR since styles are inlined anyway (checked with Postman)
if (file.resourceType === 'script') {
file.css = [];
}
}
},
},
}); and every component inside pages/layouts which is below the fold is wrapped in NuxtLazyHydrate and prefixed with Lazy <template>
<!-- components below the fold -->
<NuxtLazyHydrate when-visible>
<LazyExampleComponent />
</NuxtLazyHydrate>
</template> this way I was able to improve Lighthouse score from 29 to 93. |
Thx @simkuns will test it out! |
Environment
Describe the issue
I am using dynamic import to import icons conditionally but I don't want to prefetch them.
This might stack up to many unused icons because it prefetches all icons from the
./icons
folder.When I want to load just Twitter icon, everything is imported.
Code
The text was updated successfully, but these errors were encountered: