Next.js Discord

Discord Forum

Remove unused CSS

Unanswered
Wuchang bream posted this in #help-forum
Open in Discord
Wuchang breamOP
Hey, how can I remove unused CSS? It shows that on pagespeed, I tried using purgecss and it was down from 400kb to 170kb, but I think tailwind wasnt working.
useLightningCss doesnt look like it changes anything
LightningCss doesnt look like its compatible with tailwind

13 Replies

Asian black bear
Tailwind does not produce unused CSS, that's the whole point of it. In only generates the classes you reference in your code. Anything beyond 15 KB is very suspicious and likely configured wrong, e.g. accidentally parsing the node_modules folder etc. You should investigate your CSS files in the network tab and see what ends up in there and whether there is any indication where it's coming from.
im talking about 400kb uncompressed normal file size
compressed is 60kb
Wuchang breamOP
this //"./node_modules/@heroui/theme/dist/*/.{js,ts,jsx,tsx}",
increases my css by 220kb, how to improve that?
Asian black bear
Nothing you can really do about it. When you import such a heavy component library it will force you to include its styles. I also doubt it's easy to manually "tree-shake" and pluck only the styles you really need.
Assuming there are truly unused styles in there. Since I'm not using this library I can't say anything about its structure.
Also it may not be an issue in the first place since Tailwind consolidates styles into a single file that eventually gets cached anyways.
Having users download a 50KB file once isn't the end of the world, especially when your JS bundle is more than thrice the size of it.
@Asian black bear Having users download a 50KB file once isn't the end of the world, especially when your JS bundle is more than thrice the size of it.
Wuchang breamOP
how to minimize the js bundle then? im pretty sure theres unused code
Wuchang breamOP
#Make Javascript bundle smaller