Improving Compression - contivero/hasmin GitHub Wiki
A big part of CSS is case-insensitive (specially when used to style HTML). As such, Hasmin lowercases most of its output to aid gzip’s algorithm compress better. Among the usual stuff such as color values and property names, Hasmin lowercases:
-
Font families, (i.e. <font-family> values), since according to §5.1 of CSS Fonts Module Level 3, UAs must much font family names case insensitively.
-
Unquoted parameters to the
local()
function in thesrc
property (See §4.3). -
Character encodings written as a <string> in the
@charset
rule. E.g.@charset "UTF-8"
may be rewritten as@charset "utf-8"
-
Common values and functions written by developers in camelCase, such as
currentColor
ortranslateZ()
Lowercasing is one of the most consistent ways of reducing the final compressed size. Nonetheless, disable with --no-lowercasing
if needed.
Values of type <string> are enclosed between either single, or double quotes. To
increase repetition, and potentially avoid a character from being include in the
Huffman tree of literals, quotation marks can be normalized. This means
converting all the <string>s to use double, or single quotes, if possible.
Ideally, the file would be analyzed to find the appropriate quotes to use,
although currently Hasmin just tries to convert everything to double quotes.
If desired, it can be disabled with --no-quote-normalization
.
Declarations may be freely reordered as long as there is not interdependency
between them (e.g. between shorthands and their longhands). Currently, only a naive lexicographical ordering is implemented; this is unsafe and thus disabled by default, but can be enabled using the --sort-declarations
flag.
Contrary to the case with declarations, selectors in a selector list may be
shuffled without restrictions. Currently, only a lexicographical order is
supported, and enabled by default. The gzip gains by doing this tend to be modest at best, and sometimes might even be detrimental. If that’s the case, disable with --no-selector-sorting
.