Skip to content

Instantly share code, notes, and snippets.

@xem
Forked from 140bytes/LICENSE.txt
Last active December 16, 2015 17:40
Show Gist options
  • Save xem/5472247 to your computer and use it in GitHub Desktop.
Save xem/5472247 to your computer and use it in GitHub Desktop.
CSS mini minifier 0.6

New version: https://gist.github.com/xem/5476454 !

CSS miniMinifier 0.6

Project page: http://xem.github.io/miniMinifier/ (you can customize your minifier there, from 80 to 328 bytes)

This entry represents the 129 bytes build (color minification not included). It's the most I can put in one tweet.

129 bytes is the length of the expression, not including the function around. 140byt.es allows that, right?

This code takes CSS code and:

  • Removes spaces, tabs, line breaks, comments
  • Remove leading zeros and units after 0
  • Preserves old IE comptibility
function(c,r){ // c = css code, r = placeholder for "replace"
return
c[r='replace'](/((\/\*[^]*?\*\/)|\s)+/g,' ') // replace all comments and spaces, tabs, line breaks with one space
[r](/^ | $|[ ;]*([^\w.#) ]) *| (\))/g,'$1$2') // remove spaces around every "safe character": { } ; , : ! + > ~ ( - @, remove semicolon before }, and keep one space between ) and "unsafe characters": a-z A-Z 0-9 # . (for old IE compatibility)
[r](/(\D)((0)[a-z%]+|0(\.))/gi,'$1$3$4') // remove leading zero and unit after 0
}
function(c,r){return c[r='replace'](/((\/\*[^]*?\*\/)|\s)+/g,' ')[r](/^ | $|[ ;]*([^\w.#) ]) *| (\))/g,'$1$2')[r](/(\D)((0)[a-z%]+|0(\.))/gi,'$1$3$4')}
// ^ 129 bytes expression starts here.
{
"name": "miniMinifier",
"description": "CSS minifier",
"keywords": [
"css",
"minifier"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>undefined</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
window.open("http://xem.github.io/miniMinifier/");
</script>
@xem
Copy link
Author

xem commented Apr 28, 2013

this is obsolete: see the new version here:
https://gist.github.com/xem/5476454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment