Hi!
XWIKI-19937 asks to replace YUI Compressor, which still minifies all our CSS years after JavaScript moved to the Closure Compiler (XWIKI-13775). While choosing a replacement, I realized: do we still need CSS minification at all?
History of CSS minification in XS
CSS minification was never decided on its own. It came with JavaScript minification in 2008-2009:
- the goal was improving page load time, when Albatross loaded about 20 JS and CSS files over HTTP/1.1 and gzip was left to the admin’s Apache config (devs list, 2007).
- YUI was chosen because “there is nothing else that does variable minimization” (devs list, 2008), a JavaScript-only argument.
- CSS was added as “it [would] also be nice to minify albatross / toucan css files” (XWIKI-1701, done in XWIKI-3958).
Over the years, it created a few things we now have to maintain:
- The debugging machinery. Minified sources are hard to debug, which led to the
?minify=falseparameter (2013), thedebug.minifyconfiguration (2015), the.min.cssfile pairs and their lookup ingetSkinFile(2020), and ~20 hard-coded.min.cssreferences. - Bugs. YUI’s last release is from 2013, and the
yuicompressor-maven-pluginrepository is archived. It breaks 13 recent CSS features (evaluation):calc()with+(XWIKI-21246, 2023, reported again as XWIKI-23906, 2026);- SVG data URLs (XWIKI-22206, 2024);
0s, keyframe0%,@container,@scope,@supports not, relative colors…
- Live bugs:
font-size: 1.0embecomes the invalidfont-size:1.0in the notifications macro and the tag cloud, and& :hoverbecomes&:hoverin Solr search. - Workarounds:
.001sinstead of0sin the tour (2026);- an implicit transition duration in the CKEditor content sheet (2026);
- a
/*!comment around the Velocity code ofstyle.cssandcssVariablesInit.css. A side effect is that these two files have never been minified.
What minification saves today
Measured with a modern minifier on all the CSS of XWiki Standard, after Velocity:
- 23 KB gzipped across our 140 style sheets: 13.6 KB for the build-time files and 8.5 KB for the skin extensions. A page loads only some of them: on the design.xwiki.org home page, minification saves about 6 KB gzipped on a cold cache.
- Skin files and webjars are cacheable for 30 days with versioned URLs, so a browser pays this once per upgrade.
- With compression, even on slow 4G and over HTTP/2 or HTTP/3, that’s about a 30 ms gain on a first visit after an upgrade, and no gain as soon as the CSS is cached.
- Most production setups compress responses at the proxy, as our admin guide recommends. Without compression the gain is about 3 times larger.
- Our biggest sheet,
style.css(249 KB, 37 KB gzipped, a third of all our CSS), is never minified (because of the workaround described above), and it wasn’t considered an issue.
Options
Both options I’ll consider do remove YUI Compressor, which means at least:
- The
yuicompressor-maven-plugingoes away from the xwiki-commons plugin management, thewebjarlifecycle and the two platform modules. - The three CSS bundles are produced by a plain concatenation and lose their
.min. We can use themaven-antrun-pluginwith<concat>for this, similarly to what we do for legacy components.- This keeps the number of requests unchanged. YUI did this bundling, and historically it was a bigger win than the minification itself. Each extra request waits for a free connection on HTTP/1.1, so serving the 5 files of
xwiki.bundle.cssseparately would cost about 300 ms more on slow 4G. Over HTTP/2 or HTTP/3, the requests share a single connection and the difference drops to 0 to 4 ms. A plain concatenation is cheap and simple anyway, so we can keep the bundles.
- This keeps the number of requests unchanged. YUI did this bundling, and historically it was a bigger win than the minification itself. Each extra request waits for a free connection on HTTP/1.1, so serving the 5 files of
- The ~20 hard-coded
.min.cssreferences are updated to target the actual source instead of the.min. For backward compatibility, a request for afoo.min.cssthat doesn’t exist servesfoo.css, with a deprecation warning.
JavaScript minification is not impacted by these changes.
Half of our build-time CSS files are Velocity templates, which a real CSS parser can’t read. So if we keep minifying, it would only make sense to have it happen at runtime, after Velocity. The best engine I found for this is css4j:
- 2 broken features against 13 for YUI, with a fallback to the source itself on a parse error;
- 5 to 9 ms for all the XS skin extensions, against 42 to 54 ms for YUI;
- around the same gain: 27% gzipped, against 28%;
- already a platform dependency, and maintained.
Here are the two options I ended up with:
- Stop minifying CSS altogether. Skin extensions are served as written, and the admin guide states that compression is what keeps CSS small. We increase the typical CSS bytes by about 10% on a cold cache (CSS is about 10% of a cold page load, so under 1% of the page weight, measured on the design.xwiki.org home page), and contrib extensions using the
webjarpackaging lose their CSS minification too. - Minify at runtime with css4j, on skin extensions, skin files and evaluated webjars. It keeps the ~6 KB gain per page, but needs new code in
SkinActionand the WebJars handler. That code runs only on a cache miss, and costs less than YUI on skin extensions today.
Alternatives I rejected:
- Another build-time minifier: only a custom token-based tool could actually read Velocity source and be useful.
- ph-css: more bugs than css4j, and it refuses 7 recent features (
clamp(),if()…). - Keeping YUI: the bugs stay, and the workarounds keep piling up as we convert LESS to CSS.
Opinion
I prefer option 1: about 6 KB gzipped per page on a cold cache isn’t worth a minifier, the workarounds and the .min machinery IMO. It simplifies the codebase instead of complexifying it, with a minimal page weight regression.
Conclusion
- Do we still need CSS minification? Should we stop minifying CSS (option 1) or switch to css4j (option 2)?
- Are you OK with dropping the
.min.cssnames, with a deprecated fallback for existing references?
Thank you in advance for your help on the topic!
Lucas C.