From 0bc376980248f421c50b039beb869dd46cd9b043 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 28 Sep 2015 20:30:20 -0400 Subject: [PATCH] Make CSSmin the default CSS compressor --- HISTORY.txt | 5 ++++- config.php | 4 ++-- docs/FAQ.wiki.md | 10 ---------- lib/Minify.php | 4 ++-- lib/Minify/CSS.php | 2 ++ lib/Minify/CSS/Compressor.php | 10 +++++++++- lib/Minify/Controller/Page.php | 2 +- min_extras/tools/minifyTextarea.php | 6 +++--- min_extras/tools/minifyUrl.php | 2 +- min_unit_tests/_test_files/html/before.min.html | 8 ++------ min_unit_tests/_test_files/html/before2.min.html | 8 ++------ min_unit_tests/_test_files/minify/minified.css | 7 ++----- min_unit_tests/test_Minify.php | 2 +- min_unit_tests/test_Minify_HTML.php | 4 ++-- 14 files changed, 33 insertions(+), 41 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index 464251c5..7ae06c91 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -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 diff --git a/config.php b/config.php index dfe13f25..a783827c 100644 --- a/config.php +++ b/config.php @@ -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'); /** diff --git a/docs/FAQ.wiki.md b/docs/FAQ.wiki.md index 1b0edb0a..913a2c16 100644 --- a/docs/FAQ.wiki.md +++ b/docs/FAQ.wiki.md @@ -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. diff --git a/lib/Minify.php b/lib/Minify.php index 1ba176ab..9c8ab243 100644 --- a/lib/Minify.php +++ b/lib/Minify.php @@ -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 @@ -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); diff --git a/lib/Minify/CSS.php b/lib/Minify/CSS.php index 32414551..ef4c5d9e 100644 --- a/lib/Minify/CSS.php +++ b/lib/Minify/CSS.php @@ -13,6 +13,8 @@ * @package Minify * @author Stephen Clay * @author http://code.google.com/u/1stvamp/ (Issue 64 patch) + * + * @deprecated Use Minify_CSSmin */ class Minify_CSS { diff --git a/lib/Minify/CSS/Compressor.php b/lib/Minify/CSS/Compressor.php index c6cdd8b7..f4fc2975 100644 --- a/lib/Minify/CSS/Compressor.php +++ b/lib/Minify/CSS/Compressor.php @@ -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 * @author http://code.google.com/u/1stvamp/ (Issue 64 patch) + * + * @deprecated Use CSSmin (tubalmartin/cssmin) */ class Minify_CSS_Compressor { diff --git a/lib/Minify/Controller/Page.php b/lib/Minify/Controller/Page.php index b17031f6..5668c63a 100644 --- a/lib/Minify/Controller/Page.php +++ b/lib/Minify/Controller/Page.php @@ -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']); diff --git a/min_extras/tools/minifyTextarea.php b/min_extras/tools/minifyTextarea.php index bee08982..49a4d504 100644 --- a/min_extras/tools/minifyTextarea.php +++ b/min_extras/tools/minifyTextarea.php @@ -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)); @@ -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') ); } diff --git a/min_extras/tools/minifyUrl.php b/min_extras/tools/minifyUrl.php index fb78c925..9ffe7288 100644 --- a/min_extras/tools/minifyUrl.php +++ b/min_extras/tools/minifyUrl.php @@ -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'); } } diff --git a/min_unit_tests/_test_files/html/before.min.html b/min_unit_tests/_test_files/html/before.min.html index 7ec603d9..deaf0d6d 100644 --- a/min_unit_tests/_test_files/html/before.min.html +++ b/min_unit_tests/_test_files/html/before.min.html @@ -7,12 +7,8 @@ name="robots" content="all" />css Zen Garden: The Beauty in CSS Design */ css Zen Garden: The Beauty in CSS Design array('Minify_CSS', 'minify') + 'cssMinifier' => array('Minify_CSSmin', 'minify') ,'jsMinifier' => array('JSMin\\JSMin', 'minify') )); $time = microtime(true) - $time; @@ -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;