Skip to content

Instantly share code, notes, and snippets.

@xem xem/LICENSE.txt forked from 140bytes/LICENSE.txt
Last active Dec 16, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.