Reduce unused javascript (nuxt)
After
nuxt generate
about 50% of index.js is not even used on the home page, can it be changed somehow?20 Replies
Unknown Userβ’15mo ago
Message Not Public
Sign In & Join Server To View
@manniL / TheAlexLichter You have example for this ?
Very project specific IMO
my project have the same problem
i saw the file in my project and the lib (nuxt3-leaflet) is responsible for more than 50%
have a option for included a lib only in page necessary?
There are many options. I can discuss it with you if you feel like, hit me in DM
(it depends on your project, on how many plugins you have, on how things get thrown around etc etc.)
of course, you can always lazy-load dependencies π
but as Rigo said, it depends a lot on the project
Will that affect only bundling? Component still be server side rendered, right?
you have a example using lazy-load dependencies
it will effect bundling + what JS is loaded when but SSR will still work
@manniL / TheAlexLichter @Rigo
I'm using SSR with Lazy in the components, but it doesn't work. the site still contains a lot of unused JS.
I've seen several configs, in vite, rollup, nitro and nuxt but all note remove the unused js
Can we see your plugins?
How are you loading external libraries?
These are modules
Do you have any plugins?
Are you registering global components somewhere?
I think I found the culprit
GitHub
Nuxt-Leaflet/src/runtime/leaflet-runtime.ts at main Β· Gugustinette/...
A Nuxt 3 module to use Leaflet. Contribute to Gugustinette/Nuxt-Leaflet development by creating an account on GitHub.
Nuxt leaflet module contains a plugin that load the whole leaflet package
Which results as unused code in a page without leaflet map
leaflet v1.9.4 β Bundlephobia
Find the size of javascript package leaflet v1.9.4. Bundlephobia helps you find the performance impact of npm packages.
In this case, what is the best way to import?
GitHub
GitHub - vue-leaflet/vue-leaflet: vue-leaflet compatible with vue3
vue-leaflet compatible with vue3. Contribute to vue-leaflet/vue-leaflet development by creating an account on GitHub.
No, I just ignored it, now I wish that my biggest problem was unused javascript π