Performance: Tailwind CSS with Remix
This affects page load speed by controlling CSS bundle size and rendering performance by how styles are applied and updated.
import tailwindStyles from './tailwind.css'; export const links = () => [{ rel: 'stylesheet', href: tailwindStyles }]; export default function App() { return <div className="p-4 m-4 bg-blue-500 text-white">Hello Remix</div>; }
import './tailwind.css'; export default function App() { return <div className="p-4 m-4 bg-blue-500 text-white">Hello Remix</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full Tailwind CSS import without purge | Minimal | 0 | High due to large CSS | [X] Bad |
| Purged Tailwind CSS with Remix links | Minimal | 0 | Low due to small CSS | [OK] Good |
links function to add global CSS files like Tailwind's stylesheet.links function to add Tailwind CSS stylesheet -> Option Bexport default function Button() {
return (
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Click Me
</button>
);
}bg-blue-500 sets a blue background, text-white sets white text, and hover:bg-blue-700 darkens the blue on hover.export default function Header() {
return (
<header className="flex justify-center items-center bg-gray-200 p-4">
<h1 class="text-3xl font-bold">Welcome</h1>
</header>
);
}className, not class.<h1> uses class which will cause a syntax warning or error in React/Remix.class instead of className in JSX -> Option Dflex flex-col sets vertical stacking by default, and md:flex-row changes to horizontal on medium screens and up.items-center centers items vertically, justify-between spaces them horizontally, and p-4 adds padding.flex on small screens; "flex-row flex-col items-center justify-between p-4" has conflicting flex directions.Pass the test and this pattern moves unknown