Step 2: Evaluation of the CSS minifiers

Last modified by Lucas Charpentier on 2026/10/30 11:03

Step 2 of Replacement for the yuicompressor maven plugin, run on 2026-10-30 against xwiki-platform master. The harness, the fixtures and the raw results are attached to this page.

Summary

  • YUI Compressor breaks a lot of current CSS, including two bugs that are live in XWiki Standard today, see Live bugs in XWiki Standard.
  • No candidate can replace YUI on both paths. Half of the build-time CSS files are Velocity templates. The real CSS parsers, css4j and ph-css, either refuse them or break them silently: css4j turns $theme.textPrimaryColor into \$theme\.textPrimaryColor, which Velocity then outputs as it is.
  • Runtime, after Velocity: css4j is the most correct and the fastest. The only 2 defects found are serialization bugs, easy to report upstream.
  • Build time: stripping the comments and collapsing the white space never broke anything in the corpus. It saves 24% gzipped, against 28% for YUI, about 2 KB in total.
  • Direction to discuss in step 3: css4j at runtime, keeping the source unminified on a parse error; a comment and white space stripper at build time. Later, optionally: minify the Velocity-rendered skin files at runtime too, so that css4j becomes the only engine.

Method

Corpus

175 style sheets:

  • the 64 build-time CSS files listed in the inventory, 33 of them Velocity templates;
  • the 76 non-empty style sheet extension objects of type CSS found in the XARs, 44 of them parsed with Velocity;
  • 35 fixtures: the cases of XWIKI-21246, XWIKI-22206 and yui/yuicompressor#330, plus modern CSS: nesting, relative colors, @supports, @container, @layer, @scope, @property, attr() with type(), if(), custom properties, math functions.

The LESS objects are left out: less4j already compresses its output before YUI runs.

Scenarios

  • Runtime: Velocity renders the CSS, then the engine minifies it. This is what happens to skin extensions.
  • Build time: the engine minifies the raw template, then Velocity renders it. This is what happens to the skin files.

Velocity runs with stubs: $theme returns one color for every key, $xwiki.getSkinFile returns a URL, #template outputs nothing. Other references and macros stay unrendered, the same way in the reference and in the result.

Oracle

Chromium 149 parses the reference, which is the unminified rendering, and the result, with CSSStyleSheet.replaceSync. Rules are matched by selector or at-rule header, then compared declaration by declaration. A different value counts as equivalent when both give the same computed value on a probe element, for example bold and 700. Anything else, or a lost rule or declaration, counts as changed.

The changed sheets were then reviewed by hand. A sheet counts as invisible only when all its changes have no visible effect, for example outline: none turned into outline:0: the computed outline width differs, but no outline is drawn either way.

The control engine, strip, gives no difference at all on the 175 sheets, which shows that the oracle does not report white space or comments as changes.

Engines

EngineVersion testedLatest releaseLicenseNotes
YUI Compressor2.4.82.4.8, July 2013BSDBaseline. Embeds Rhino 1.7R2.
css4j6.26.2, December 2025BSD 3-clauseReal CSS parser. Already a platform dependency. Published on its own Maven repository, not on Maven Central.
ph-css8.2.38.2.3, October 2026Apache 2Real CSS parser. Pulls about 8 ph-commons JARs. The error handler API used here is deprecated for removal.
logicsquad minifier2.02.0, October 2026BSD 2-clauseToken-based, port of CSSMin. No dependency. Maven plugin 1.5.
Lightning CSS1.331.33.0, July 2026MPL 2.0Rust, Node binding. Runtime scenario only, as a size reference.
stripn/an/an/aControl written for this evaluation, about 60 lines: removes the comments except /*! ones and collapses the white space, keeping new lines and strings.

Every engine was tested in its latest release. The yuicompressor-maven-plugin we use to run YUI at build time had its last release, 1.5.1, in November 2014, and its GitHub repository is archived. The repositories of css4j, ph-css, logicsquad minifier and Lightning CSS all received commits in October 2026.

css4j and ph-css run in two modes: safe keeps the source unminified when the parser reports an error, lenient ignores the errors.

Results

Correctness, runtime scenario

EngineUnchangedEquivalentInvisible onlyChangedKept unminified
YUI135186160
logicsquad13337140
css4j safe1639129
css4j lenient1599160
ph-css safe16651319
ph-css lenient1605199
strip1750000

The sheets kept unminified are also counted as unchanged.

Lightning CSS merges and rewrites rules, for example media queries into range syntax, which this oracle reports as lost rules. Its 52 changed sheets are mostly such rewrites and were not reviewed one by one.

Real defects behind the changed sheets:

  • YUI:
    • declarations dropped because spaces around + and - are removed in calc(), also inside min(), max() and clamp(), or inside relative colors: XWIKI-21246;
    • spaces removed inside an SVG data URL: XWIKI-22206;
    • 0s turned into 0, which drops the whole transition;
    • keyframe selector 0% turned into 0, which drops the keyframe;
    • flex: 1 1 0% turned into 1 1 0px, which is not the same flex basis;
    • @container card (width > 400px), @supports (not (...)) and @scope (.a) to (.b) lose spaces and stop matching;
    • @property with initial-value: 0deg turned into 0, which drops the rule;
    • font-size: 1.0em turned into font-size: 1.0, and & :hover into &:hover, see below.
  • logicsquad: an empty custom property, --empty: ;, swallows the next declaration; same flex: 1 1 0% bug as YUI. Its 2 other changed sheets come from Velocity macros the stub does not render.
  • css4j: keyframe selector 0% serialized as 0; @supports selector(:has(a)) serialized without its space.
  • ph-css: 0s turned into 0; flex: 1 1 0% bug; @property initial-value: 0deg turned into 0. It also refuses many modern constructs, if(), attr() with type(), clamp(), and keeps those sheets unminified.

The invisible changes are YUI rewriting outline: none and background: none, as described in the build-time scenario below, and the other engines shortening a color inside a custom property, for example white into #fff.

In lenient mode, css4j and ph-css silently drop what they do not understand. ph-css drops the declarations using clamp(), if() or attr() with type(). css4j outputs nothing at all for a sheet starting with an @import that uses layer() and supports().

Correctness, build-time scenario

EngineUnchangedEquivalentInvisible onlyChangedTemplate brokenKept unminified
YUI47125000
logicsquad47140030
css4j safe60301031
css4j lenient30303100
ph-css safe61300033
ph-css lenient60301032
strip6400000
  • YUI changes no file visibly. Its 5 invisible changes:
    • outline: none becomes outline:0. The outline width goes from medium to 0, but the outline style stays none, so no outline is drawn.
    • background: none becomes background:0, which sets the background position to 0 center instead of 0% 0%. There is no background image to position, so nothing changes.
  • logicsquad breaks 3 templates. For example it drops the ] closing a list in the arguments of the #css3_backgroundLinearGradient macro in dashboard.css, so Velocity cannot parse the file any more.
  • css4j and ph-css in safe mode refuse about half of the files, the Velocity templates, which then ship unminified. When css4j accepts a template, it can still break it: in print.css it escapes $theme.textPrimaryColor into \$theme\.textPrimaryColor, so the color is lost.
  • In lenient mode they drop or escape the Velocity code: css4j changes 31 of the 64 files.

Size

Build time, the 64 raw templates:

EngineRawSavedGzippedSaved
none136.5 KB 47.7 KB
YUI98.1 KB28%34.4 KB28%
logicsquad97.9 KB28%34.4 KB28%
css4j safe119.3 KB13%40.9 KB14%
ph-css safe122.2 KB10%42.0 KB12%
strip108.0 KB21%36.3 KB24%

Runtime, the 76 skin extension objects after Velocity:

EngineRawSavedGzippedSaved
none80.3 KB 31.3 KB
YUI54.8 KB32%22.5 KB28%
logicsquad54.5 KB32%22.5 KB28%
css4j safe56.8 KB29%23.0 KB27%
ph-css safe57.3 KB29%23.2 KB26%
Lightning CSS53.1 KB34%21.9 KB30%
strip61.7 KB23%24.2 KB23%

Speed

Time to minify the 175 rendered sheets, 217 KB, once, after warm-up. The machine was shared, so the figures varied between runs; the ranking did not.

EngineTime per pass
strip5 to 10 ms
css4j30 to 50 ms
logicsquad40 to 60 ms
ph-css110 to 140 ms
YUI150 to 260 ms

css4j was 3 to 8 times faster than YUI, depending on the run.

Support of recent CSS features

Each row is one feature, minified at runtime and checked in Chromium against the unminified source. The rows come from the fixtures, plus the two constructs behind the live bugs. css4j and ph-css run in safe mode: kept unminified means the engine refused the sheet, so it is correct but not smaller. Lightning CSS is left out because its rewrites could not be judged automatically.

FeatureExampleYUIlogicsquadcss4jph-css
calc() with + or -calc(50% + 1px), calc(50% - (100px / 2))Broken: XWIKI-21246OKOKOK
Operators in min(), max(), clamp()clamp(1rem, 0.5rem + 2vw, 2rem)BrokenOKOKKept unminified
Zero timestransition: opacity 0s .2sBrokenOKOKBroken
SVG in a data URLurl("data:image/svg+xml,%3Csvg viewBox='0 0 10 10'%3E…")Broken: XWIKI-22206OKOKOK
Keyframe selector 0%@keyframes fade { 0% {…} }BrokenOKBrokenOK
Percentage flex basisflex: 1 1 0%BrokenBrokenOKBroken
Number with a unitfont-size: 1.0emBrokenOKOKOK
Nesting& .title, &:hoverOKOKOKOK
Nesting with a descendant pseudo-class& :hoverBrokenOKOKOK
@propertyinitial-value: 0degBrokenOKOKBroken
Named container queries@container card (width > 400px)BrokenOKOKOK
@supports with not@supports (not (display: grid))BrokenOKOKKept unminified
@supports selector()@supports selector(:has(a))OKOKBrokenKept unminified
@scope@scope (.card) to (.content)BrokenOKOKOK
Relative colorsoklch(from var(--c) calc(l + 0.1) c h)BrokenOKOKOK
Unusual custom property values--empty: ;, --json: { "a": 1 }OKBrokenKept unminifiedKept unminified
@import with layer() and supports()@import url("theme.css") layer(theme) supports(display: grid)OKOKKept unminifiedKept unminified
attr() with type()attr(data-size type(<length>), 10px)OKOKOKKept unminified
if()if(style(--scheme: dark): white; else: black)OKOKOKKept unminified
@layer, @starting-style, media query ranges, :is(), :where(), :has(), grid, logical properties, color-mix()n/aOKOKOKOK

YUI breaks 13 of these features, logicsquad 2, css4j 2 and ph-css 3. ph-css also refuses 7 of them, so the sheets using them are not minified.

Workarounds in XWiki Standard today

Developers already write around the YUI bugs:

  • TourCode.TourJS uses visibility .001s .2s instead of 0s, with the comment "Using an actual 0s here gets minified to 0, which is incorrect CSS", added for XWIKI-24022 in February 2026.
  • CKEditor.ContentSheet sets transition-delay and transition-property separately and leaves the duration implicit, for the same reason, added for XWIKI-22383 in September 2026.
  • style.css and cssVariablesInit.css open with /*! and close the comment right before printing their output, so that YUI keeps their Velocity code intact at build time. As a side effect, YUI never minifies the CSS these two files output.
  • No workaround exists for calc(): XWIKI-21246 is still open and was reported again as XWIKI-23906 in January 2026. The workaround suggested in the issue, the LESS escape ~"…", does not apply to plain CSS. For SVG data URLs, encoding the spaces as %20 avoids XWIKI-22206.

Live bugs in XWiki Standard

The runtime minification already changes the rendering of these skin extensions, compared to ?minify=false:

  • .notification-content blockquote { font-size: 1.0em; } in XWiki.Notifications.Code.Macro.NotificationsMacro, and the same value in XWiki.TagCloud: YUI outputs font-size:1.0, an invalid declaration, so the font size is ignored.
  • & :hover, & :focus, & :focus-within in Main.SolrSearch: YUI outputs &:hover,&:focus,&:focus-within. The source targets a hovered or focused descendant, the minified code targets the element itself.

Limitations

  • Velocity runs with stubs, not in XWiki: macros like #css3_backgroundLinearGradient and references like $services stay unrendered.
  • One browser engine, Chromium. The oracle compares declarations and computed values on a probe element, not the layout of real pages.
  • The fixtures were written for this evaluation and do not cover everything.

Consequences for step 3

  • Runtime: css4j in safe mode. Report its 2 serialization bugs upstream, the keyframe 0% and the @supports selector() space, first.
  • Build time: a real CSS parser cannot work on raw Velocity templates. Options:
    • a comment and white space stripper, owned by XWiki, small and safe, for a 4% smaller gain than YUI;
    • logicsquad minifier: same gain as YUI, but it breaks 3 templates;
    • no build-time minification for the Velocity templates, and minify the rendered skin files at runtime with css4j, as for skin extensions. This gives a single engine, at the cost of a bigger change in how skin files are served.
  • The webjar CSS can also contain Velocity, when it is loaded with 'evaluate': true, so the same constraint applies to the webjar packaging.

Get Connected