Skip to content

Commit

Permalink
Make CSSmin the default CSS compressor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclay committed Sep 29, 2015
1 parent db1ea29 commit 0bc3769
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 41 deletions.
5 changes: 4 additions & 1 deletion HISTORY.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Minify Release History

(master)
Version 3.0.0
* Better CSS minification via Túbal Martín's CSSMin
* New API incompatible with the 2.x versions
* Installation requires use of Composer to install dependencies
* Builder styled with Bootstrap (thanks to help from acidvertigo)
* Add config option for simply concatenating files

Expand Down
4 changes: 2 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@


/**
* To use CSSmin (Túbal Martín's port of the YUI CSS compressor), uncomment the following line:
* To use the CSS compressor that shipped with 2.x, uncomment the following line:
*/
//$min_serveOptions['minifiers']['text/css'] = array('Minify_CSSmin', 'minify');
//$min_serveOptions['minifiers'][Minify::TYPE_CSS] = array('Minify_CSS', 'minify');


/**
Expand Down
10 changes: 0 additions & 10 deletions docs/FAQ.wiki.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
## Why do the CSS & HTML minifiers add so many line breaks?

TL;DR: Ignore them. They don't add to the output size and if you absolutely want all content on one line you will have to use another tool.

It's [rumored](https://github.com/yui/yuicompressor/blob/master/doc/README#L43) that some source control tools and old browsers don't like very long lines. Compressed files with shorter lines are also easier to diff.

Since both Minify classes are regex-based, it would be very difficult/error-prone to count characters then try to re-establish context to add line breaks. Instead, both classes trade 1 space for 1 line break (`\n`) wherever possible, adding breaks but without adding bytes.

If you can think of another safe & efficient way to limit lines in these two tools without adding bytes, please submit a patch, but this is not something anyone should be worrying about.

## Minify doesn't compress as much as product XYZ. Why not?

Out of the box, Minify uses algorithms available in PHP, which frankly aren't as solid as competing products, but I consider them _good enough_. At this point I don't have time to work on further tweaking, so if you must have _perfect_ minification you can explore the CookBook to plug in other minifiers. If you'd like to propose specific tweaks in the algorithm (and don't have a patch), please propose these in the Google Group, not the issue tracker.
Expand Down
4 changes: 2 additions & 2 deletions lib/Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function getDefaultOptions()

'minifiers' => array(
Minify::TYPE_JS => array('JSMin\\JSMin', 'minify'),
Minify::TYPE_CSS => array('Minify_CSS', 'minify'),
Minify::TYPE_CSS => array('Minify_CSSmin', 'minify'),
Minify::TYPE_HTML => array('Minify_HTML', 'minify'),
),
'minifierOptions' => array(), // no minifier options
Expand Down Expand Up @@ -293,7 +293,7 @@ public function serve(Minify_ControllerInterface $controller, $options = array()
if ($this->options['contentType'] === self::TYPE_JS) {
$source->setMinifier("");
} elseif ($this->options['contentType'] === self::TYPE_CSS) {
$source->setMinifier(array('Minify_CSS', 'minify'));
$source->setMinifier(array('Minify_CSSmin', 'minify'));
$sourceOpts = $source->getMinifierOptions();
$sourceOpts['compress'] = false;
$source->setMinifierOptions($sourceOpts);
Expand Down
2 changes: 2 additions & 0 deletions lib/Minify/CSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @package Minify
* @author Stephen Clay <[email protected]>
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
*
* @deprecated Use Minify_CSSmin
*/
class Minify_CSS {

Expand Down
10 changes: 9 additions & 1 deletion lib/Minify/CSS/Compressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@
* including the ie5/mac filter (and its inversion), but expect tricky
* hacks involving comment tokens in 'content' value strings to break
* minimization badly. A test suite is available.
*
*
* Note: This replaces a lot of spaces with line breaks. It's rumored
* (https://github.com/yui/yuicompressor/blob/master/README.md#global-options)
* that some source control tools and old browsers don't like very long lines.
* Compressed files with shorter lines are also easier to diff. If this is
* unacceptable please use CSSmin instead.
*
* @package Minify
* @author Stephen Clay <[email protected]>
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
*
* @deprecated Use CSSmin (tubalmartin/cssmin)
*/
class Minify_CSS_Compressor {

Expand Down
2 changes: 1 addition & 1 deletion lib/Minify/Controller/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function createConfiguration(array $options) {
if (isset($options['minifyAll'])) {
// this will be the 2nd argument passed to Minify_HTML::minify()
$sourceSpec['minifyOptions'] = array(
'cssMinifier' => array('Minify_CSS', 'minify')
'cssMinifier' => array('Minify_CSSmin', 'minify')
,'jsMinifier' => array('JSMin\\JSMin', 'minify')
);
unset($options['minifyAll']);
Expand Down
6 changes: 3 additions & 3 deletions min_extras/tools/minifyTextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function h($txt) {
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin\\JSMin', 'minify');
}
if (isset($_POST['minCss'])) {
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSSmin', 'minify');
}
$source = new Minify_Source($sourceSpec);
Minify_Logger::setLogger(FirePHP::getInstance(true));
Expand All @@ -50,14 +50,14 @@ function h($txt) {
}

$tpl = array();
$tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_CSSmin', 'JSMinPlus');
$tpl['classes'] = array('Minify_HTML', 'JSMin\\JSMin', 'Minify_CSS', 'Minify_CSS', 'JSMinPlus');

if (isset($_POST['method']) && in_array($_POST['method'], $tpl['classes'])) {

$args = array($textIn);
if ($_POST['method'] === 'Minify_HTML') {
$args[] = array(
'cssMinifier' => array('Minify_CSS', 'minify')
'cssMinifier' => array('Minify_CSSmin', 'minify')
,'jsMinifier' => array('JSMin\\JSMin', 'minify')
);
}
Expand Down
2 changes: 1 addition & 1 deletion min_extras/tools/minifyUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function sniffType($headers) {
$sourceSpec['minifyOptions']['jsMinifier'] = array('JSMin\\JSMin', 'minify');
}
if (isset($_POST['minCss'])) {
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSS', 'minify');
$sourceSpec['minifyOptions']['cssMinifier'] = array('Minify_CSSmin', 'minify');
}
}

Expand Down
8 changes: 2 additions & 6 deletions min_unit_tests/_test_files/html/before.min.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
name="robots" content="all" /><title>css Zen Garden: The Beauty in CSS Design</title> <script type="text/javascript">var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}</script> <script type="text/javascript">/*<![CDATA[*/var i=0;while(++i<10)
{}/*]]>*/</script> <script type="text/javascript">i=1;</script> <script type="text/javascript">/*<![CDATA[*/(i<1);/*]]>*/</script> <!--[if IE 6]><style type="text/css">/*<![CDATA[*/
/*! copyright: you'll need CDATA for this < & */
body{background:white}/*]]>*/</style><![endif]--><style type="text/css" title="currentStyle" media="screen">@import "/001/001.css";/*\*/css
hack{}/**/ /*/*/css
hack{}/**/css
hack{display/**/:/**/none;display:none}</style><link
{}/*]]>*/</script> <script type="text/javascript">i=1;</script> <script type="text/javascript">/*<![CDATA[*/(i<1);/*]]>*/</script> <!--[if IE 6]><style type="text/css">/*<![CDATA[*//*! copyright: you'll need CDATA for this < & */
body{background:white}/*]]>*/</style><![endif]--><style type="text/css" title="currentStyle" media="screen">@import "/001/001.css";/*\*//**/css hack{display:none;display:none}</style><link
rel="Shortcut Icon"
type="image/x-icon"
href="http://www.csszengarden.com/favicon.ico" /><link
Expand Down
8 changes: 2 additions & 6 deletions min_unit_tests/_test_files/html/before2.min.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
name="robots" content="all"><title>css Zen Garden: The Beauty in CSS Design</title> <script type="text/javascript">var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}</script> <script type="text/javascript">var i=0;while(++i<10)
{}</script> <script type="text/javascript">i=1;</script> <script type="text/javascript">(i<1);</script> <!--[if IE 6]><style type="text/css">
/*! copyright: you'll need CDATA for this < & */
body{background:white}</style><![endif]--><style type="text/css" title="currentStyle" media="screen">@import "/001/001.css";/*\*/css
hack{}/**/ /*/*/css
hack{}/**/css
hack{display/**/:/**/none;display:none}</style><link
{}</script> <script type="text/javascript">i=1;</script> <script type="text/javascript">(i<1);</script> <!--[if IE 6]><style type="text/css">/*! copyright: you'll need CDATA for this < & */
body{background:white}</style><![endif]--><style type="text/css" title="currentStyle" media="screen">@import "/001/001.css";/*\*//**/css hack{display:none;display:none}</style><link
rel="Shortcut Icon"
type="image/x-icon"
href="http://www.csszengarden.com/favicon.ico"><link
Expand Down
7 changes: 2 additions & 5 deletions min_unit_tests/_test_files/minify/minified.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion min_unit_tests/test_Minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function test_Minify()
}

assertTrue(
! class_exists('Minify_CSS', false)
! class_exists('Minify_CSSmin', false)
,'Minify : minifier classes aren\'t loaded for 304s'
);

Expand Down
4 changes: 2 additions & 2 deletions min_unit_tests/test_Minify_HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function test_HTML()

$time = microtime(true);
$minOutput = Minify_HTML::minify($src, array(
'cssMinifier' => array('Minify_CSS', 'minify')
'cssMinifier' => array('Minify_CSSmin', 'minify')
,'jsMinifier' => array('JSMin\\JSMin', 'minify')
));
$time = microtime(true) - $time;
Expand All @@ -33,7 +33,7 @@ function test_HTML()

$time = microtime(true);
$minOutput = Minify_HTML::minify($src, array(
'cssMinifier' => array('Minify_CSS', 'minify')
'cssMinifier' => array('Minify_CSSmin', 'minify')
,'jsMinifier' => array('JSMin\\JSMin', 'minify')
));
$time = microtime(true) - $time;
Expand Down

0 comments on commit 0bc3769

Please sign in to comment.