Nuxt Don't Embed CSS in Html (Extract CSS)

Oct 5, 2020

Nuxt by default would embed quite a lot of CSS (I am not sure partial or all) into the generated HTML, thus increasing the HTML size.

For static pages, I assume it would be more efficient to store CSS in a single file which are shared by all pages.

You can do that via extractCSS.

Edit nuxt.config.js.

export default {  build: {    extractCSS: true,  },}

Using extract-css-chunks-webpack-plugin under the hood, all your CSS will be extracted into separate files, usually one per component. This allows caching your CSS and JavaScript separately and is worth a try in case you have a lot of global or shared CSS.

NOTE: You might want to check your Pagespeed (Mobile) or Lighthouse score, as sometimes those test prefer everything to be embeded rather than occuring multiple fetch.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.