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.7

CSS miniMinifier 0.7

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

This entry represents the 138 bytes build (options 1, 3, 4). The bytes count here, includes the whole function.

This function takes a string containing CSS code and:

  • Removes unnecessary spaces, tabs, line breaks, comments
  • Remove leading zeros and units after 0
  • Preserves old IE comptibility
function(c){
// replace all comments and spaces, tabs, line breaks with one space
return c.replace(/(\/\*[^]*?\*\/|\s)+/g,' ')
// remove spaces around every "safe character": { } ; , : ! + > ~ ( - @, remove semicolon before },
// keep one space between ) and "unsafe characters": a-z A-Z 0-9 # . (for old IE compatibility),
// and remove leading zero and units after values equal to zero.
.replace(/(\D)((0)[a-z%]+|0(\.))|^ | $|[ ;]*([^\w.#)'" ]) *| (\))/g,'$1$3$4$5$6')
}
function(c){return c.replace(/(\/\*[^]*?\*\/|\s)+/g,' ').replace(/(\D)((0)[a-z%]+|0(\.))|^ | $|[ ;]*([^\w.#)'" ]) *| (\))/g,'$1$3$4$5$6')}
{
"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>
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.