Production
Utility CSS from a CDN in production
Serving a complete utility stylesheet from a CDN in production is a reasonable choice for most sites. This guide puts numbers on it, explains caching and render blocking, and shows when it is worth purging the file instead.
The numbers
The production file is dist/monsoon.min.css. Measured on version 0.2.0:
| Encoding | Size |
|---|---|
| Minified, uncompressed | about 1320.5 kB |
| gzip | about 145.4 kB |
| brotli | about 88.3 kB |
CDNs and most hosts send brotli to browsers that accept it, so 88.3 kB is what a visitor downloads once. The repository has a size check that warns above 100 kB and fails above 120 kB with brotli, so the number cannot creep up unnoticed.
For comparison with everyday assets: that is less than a typical hero photo, and the stylesheet is shared by every page of the site.
Caching and pinning
Pin the version in production. A versioned URL never changes content, so the browser can keep it in cache across visits and the CDN can serve it from the edge:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss@0.2.0/dist/monsoon.min.css">Modern browsers partition their cache per site, so do not count on visitors already having the file from another website. Count on the second page view and every later visit being free.
Render blocking is a feature for CSS
Stylesheets in the head block the first paint until they load. For your main stylesheet that is exactly what you want: the alternative is a flash of unstyled content. Keep it fast by:
- placing the
<link>early in the<head>, - using
<link rel="preconnect">for the CDN host if it is a new origin for the page, - avoiding
@importchains, which make the browser discover files one after another.
There is no JavaScript to wait for. Seed theming and dark mode are computed by the CSS engine during the same style pass as everything else.
When purging is worth it
Purging removes the rules your files never mention. It is worth the extra step when the first visit matters a lot (for example a landing page for paid traffic), when you serve users on slow networks, or when you already have a deploy step anyway.
npx monsooncss purge "src/**/*.html" "src/**/*.js" -o public/monsoon.cssmonsooncss purge: scanned 1 file
kept 294 of 16351 utility rules
public/monsoon.css: 281.2 kB raw, 48.4 kB gzip, 39.2 kB brotli (full build 88.0 kB brotli)That output comes from the kitchen sink demo in the repository, a page that uses a wide mix of utilities. The purged file keeps the reset, the theme tokens and the keyframes, so seed theming and dark mode still work.
The purge command looks for class names as whole words in your files. If you build a class name from pieces at runtime, such as "bg-" + status, list the results with --safelist bg-success,bg-danger so they are kept.
Production checklist
- Pin the exact version in the URL.
- Add
integrityandcrossoriginif your security policy wants subresource integrity. - Preconnect to the CDN host, or self host the file on your own origin.
- Decide if the full file is fine. If not, purge in your deploy step and safelist dynamic classes.
- Check the page in light and dark mode, and with your seed color, before you ship.
Frequently asked questions
Is it bad practice to use a CSS framework from a CDN in production?
No, as long as you pin a version. Many production sites load CSS from public CDNs. Self host it if your security policy or privacy rules require it.
How big is Monsoon after purging?
It depends on how many classes you use. The kitchen sink demo, which uses a wide mix, purges to about 39.2 kB with brotli. Purging removes unused utilities; the reset, the theme tokens and the component layer are always kept.
Does purging break dark mode or theming?
No. The purge command always keeps the theme tokens, the dark mode switch, the reset and the keyframes. Only unused utility rules are removed.
Should I inline the CSS?
For most sites no. A cached external file is better across page views. Inlining a purged file can make sense for a single landing page.
Try it in ten seconds
Paste this into any HTML page. No install, no build.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">