Minification
U.minify_css(), U.minify_js() and U.minify_html().
On this page
API
method
U.minify_css(css)
Minifies CSS and compiles nested rules and $variables.
U.minify_css(css)| Parameter | Type | Description |
|---|---|---|
css |
String |
CSS source. |
Returns String Minified CSS.
Removes comments and whitespace, shortens margin and padding (0 0 0 0 to 0, 10px 20px 10px 20px to 10px 20px) and colours such as #FFFFFF. A rule that contains only other rules is expanded (.a { .b { } } to .a .b{}). Variables are declared as $name: value; and used as $name. On an error the function logs CSS compiler error and returns an empty string.
U.minify_css('.menu {\n\t.item { color: red; }\n\t.active { font-weight: bold; }\n}');
// '.menu .item{color:red}.menu .active{font-weight:bold}'
U.minify_css('$brand: #0066FF;\n.button { background: $brand; }');
// '.button{background:#0066FF}'
method
U.minify_js(js)
Minifies JavaScript.
U.minify_js(js)| Parameter | Type | Description |
|---|---|---|
js |
String |
JavaScript source. |
Returns String Minified code.
Removes comments, line breaks and unneeded whitespace. Strings are kept as they are. It does not rename variables.
U.minify_js('if (a) {\n\tconsole.log(a); // log\n}'); // 'if(a){console.log(a);}'
method
U.minify_html(html)
Minifies HTML.
U.minify_html(html)| Parameter | Type | Description |
|---|---|---|
html |
String |
HTML source. |
Returns String Minified HTML.
Removes comments (not conditional comments such as <!--[if IE]>) and collapses runs of spaces between words to one space. Line breaks and indentation between tags are kept. The content of script, textarea, pre, code and readme is not changed. Inline script and style are minified with the JS and CSS minificators when $minifyjs and $minifycss are on.
var html = U.minify_html(source);