#Nextjs with react and tailwind css

1 messages · Page 1 of 1 (latest)

hollow brookBOT
#

Hi @mortal palm. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, Tailwind CSS could be contributing to the size of your CSS file. Tailwind CSS is a utility-first CSS framework that generates a large number of utility classes, which can result in a large CSS file size. However, in a production build, Next.js tries to minimize the number of network requests and maximize compression by bundling CSS files if possible. This is the expected behavior in the pages directory too (source (https://github.com/vercel/next.js/issues/50239)).

However, there are ways to optimize this. One of the known slowdowns with Tailwind CSS is when the content configuration includes the entire filesystem. This means Tailwind CSS will traverse and read all possible files during bootup, which is how the Tailwind JIT compiler works. They are working on an optimization where reading the files is async after sharing the CPU profiles with them. They're also working on a new Rust-based compiler that does the crawling much faster, but still a wrong configuration could cause much more to be crawled than intended (source (https://github.com/vercel/next.js/issues/48748)).

You can also optimize the use of Tailwind CSS by properly configuring it in your Next.js application. You can add the Tailwind CSS directives that Tailwind will use to inject its generated styles to a Global Stylesheet in your application (source (https://nextjs.org/docs/app/building-your-application/styling/tailwind-css#importing-styles)).

If you're still facing issues with large CSS file sizes, it might be worth looking into other factors that could be contributing to this, such as the use of Sass or extremely large barrel files.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: