In combres file, I use defaultCssMinifierRef="msajax".
This minifier remove the units (px, em, ms) for all zero values. But 0ms is not the same as 0s. So, what I should do, if I need to save units after minification?
In combres file, I use defaultCssMinifierRef="msajax".
This minifier remove the units (px, em, ms) for all zero values. But 0ms is not the same as 0s. So, what I should do, if I need to save units after minification?
The unit identifier can be omitted only for lengths of zero. Other units require the unit identifier even for values of zero. Lengths include em
, px
, etc. There is some debate over whether it is better to include it or not (see this question and this one). A minifier will and should remove the unit identifier on lengths of zero. See the spec here:
for zero lengths the unit identifier is optional
Non-lengths require unit identifiers, whether zero or not. If a minifier removes the unit identifier of a non-length, such as the ms
in the time given as the value of the property transition-duration
, it is a bug in the minifier.
You don't ever need to save 0 values with a unit.
In CSS using a 0 without a unit means the same as as 0 with unit.
You could use top: 20px
and it would place the element 20px from the top depending on its position.
If you use top: 0
this gets translated to top: 0px
by the browser so you simply don't have to worry about that.
Your compiler will only strip the units off of the values like 0px
, 0em
because they are redundant and can simply be used as 0
instead.
If it were to strip off the value off a top: 20px
for instance, this would cause problems since the rendering engine wouldn't know if it were top: 20rem
or top: 20px
which are remarkably different when compared.
Stripping units from 0 values with units is actually a bit of an advantage as less bytes have to be sent over the network, this is only very minor but since it's an automatic process it doesn't really cost you anything as a developer (as in keeping into account that you'll manually have to strip 0 values with units from their unit).
There are however exceptions to this as @torazaburo pointed out in the comments. Times in CSS e.g. 100ms
, 0.1s
require a unit but as @torazaburo pointed out this is also automatically handled by the minifier by shortening something like 100ms
to 0.1s
to save bytes.