Performance: JIT mode and on-demand generation
This affects the CSS bundle size and page load speed by generating only the styles actually used in the HTML at build or runtime.
Jump into concepts and practice - no test required
/* Tailwind JIT mode enabled in config */ module.exports = { mode: 'jit', purge: ['./src/**/*.{html,js}'], // other config };
/* Tailwind classic mode: all styles generated upfront */
@tailwind base;
@tailwind components;
@tailwind utilities;| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Classic Tailwind (all styles) | Low (CSS only) | 1 (initial load) | High (large CSS paint) | [X] Bad |
| Tailwind JIT mode | Low (CSS only) | 1 (initial load) | Low (small CSS paint) | [OK] Good |
mode: 'jit' and content array for files.module.exports = { mode: 'jit', content: ['./index.html'] }<div class="bg-blue-500 p-4">Hello</div>
bg-blue-500 and p-4 appear, so their styles are generated.content to generate CSS on changes.content, JIT won't generate CSS for new classes.bg-${color}-500 where color is a variable. How can you ensure Tailwind JIT generates the correct CSS?