Optimizing for Production
Introductionβ
Tailwind CSS focuses on producing the smallest CSS file possible by generating only the CSS used in your project. This often results in CSS files under 10kB, even for large projects. For instance, Netflix's Top 10 site uses Tailwind and delivers just 6.5kB of CSS.
Steps to Optimizeβ
Minify CSSβ
Minifying your CSS can be done using tools like cssnano. If using Tailwind CLI, add the --minify
flag:
npx tailwindcss -o build.css --minify
PostCSS Pluginβ
If Tailwind is installed as a PostCSS plugin, add cssnano at the end of your plugin list:
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
...(process.env.NODE_ENV === "production" ? { cssnano: {} } : {}),
},
};
Compressionβ
Compress your CSS using Brotli or similar tools.
Frameworksβ
Many frameworks handle minification and compression automatically in production.
For more details, visit the Tailwind CSS documentation.