K
K
kafeman2013-04-21 17:06:01
css
kafeman, 2013-04-21 17:06:01

Smart CSS Minifier

Looking for a CSS minifier that is capable of this:

body {
  font-size: 10pt;
  font-family: Arial, sans-serif;
}
body {
  color: #333333;
}

Convert to this:

body{color:#333;font:10pt Arial,sans-serif}

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
armid, 2013-04-21
@armid

Well, if you go head-on, then your specific task is solved by devilo.us/
But you yourself understand that there can be many examples, you always need to test.

F
frostosx, 2013-04-22
@frostosx

Try this:

function minifyCSS($string)
{
  /* Strips Comments */
  $string = preg_replace('!/\*.*?\*/!s','', $string);
  $string = preg_replace('/\n\s*\n/',"\n", $string);

  /* Minifies */
  $string = preg_replace('/[\n\r \t]/',' ', $string);
  $string = preg_replace('/ +/',' ', $string);
  $string = preg_replace('/ ?([,:;{}]) ?/','$1',$string);

  /* Kill Trailing Semicolon, Contributed by Oliver */
  $string = preg_replace('/;}/','}',$string);

  /* Return Minified CSS */
  return $string;
}

I successfully use it in all projects.

V
Vitali Borovik, 2013-04-21
@WAYS

csso Before
: Now
.test0 { margin: 0 } .test1 { border: none } .test2 { border: none } .test0 { padding: 0 }
:
.test0 { margin: 0 } .test1, .test2 { border: none } .test0 { padding: 0 }

A
Antelle, 2013-04-21
@Antelle

css-condense for example. In general, look in npm for the css keyword, there are a lot of interesting things.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question