Skip to content

Commit

Permalink
Added a new CSS / JS minify library that seems to do a better job #864
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed May 31, 2016
1 parent 395e640 commit a24b7fa
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
"filp/whoops": "~2.0",
"monolog/monolog": "~1.0",
"gregwar/image": "~2.0",
"mrclay/minify": "~2.2",
"mrclay/minify": "~2.3",
"donatj/phpuseragentparser": "~0.3",
"pimple/pimple": "~3.0",
"rockettheme/toolbox": "dev-develop",
"maximebf/debugbar": "~1.10",
"ext-mbstring": "*",
"ext-openssl": "*",
"ext-curl": "*"
"ext-curl": "*",
"matthiasmullie/minify": "^1.3"
},
"require-dev": {
"codeception/codeception": "^2.1",
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

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

22 changes: 22 additions & 0 deletions system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,17 @@ form:
validate:
type: bool

assets.css_minify_old:
type: toggle
label: PLUGIN_ADMIN.CSS_MINIFY_OLD
help: PLUGIN_ADMIN.CSS_MINIFY_OLD_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

assets.css_minify_windows:
type: toggle
label: PLUGIN_ADMIN.CSS_MINIFY_WINDOWS_OVERRIDE
Expand Down Expand Up @@ -688,6 +699,17 @@ form:
validate:
type: bool

assets.js_minify_old:
type: toggle
label: PLUGIN_ADMIN.JAVASCRIPT_MINIFY_OLD
help: PLUGIN_ADMIN.JAVASCRIPT_MINIFY_OLD_HELP
highlight: 0
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

assets.enable_asset_timestamp:
type: toggle
label: PLUGIN_ADMIN.ENABLED_TIMESTAMPS_ON_ASSETS
Expand Down
2 changes: 2 additions & 0 deletions system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ assets: # Configuration for Assets Manager (
css_pipeline_include_externals: true # Include external URLs in the pipeline by default
css_pipeline_before_excludes: true # Render the pipeline before any excluded files
css_minify: true # Minify the CSS during pipelining
css_minify_old: false # Use the previous Minify library for CSS (if having issues)
css_minify_windows: false # Minify Override for Windows platforms. False by default due to ThreadStackSize
css_rewrite: true # Rewrite any CSS relative URLs during pipelining
js_pipeline: false # The JS pipeline is the unification of multiple JS resources into one file
js_pipeline_include_externals: true # Include external URLs in the pipeline by default
js_pipeline_before_excludes: true # Render the pipeline before any excluded files
js_minify: true # Minify the JS during pipelining
js_minify_old: false # Use the previous Minify library for JS (if having issues)
enable_asset_timestamp: false # Enable asset timestamps
collections:
jquery: system://assets/jquery/jquery-2.x.min.js
Expand Down
30 changes: 26 additions & 4 deletions system/src/Grav/Common/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Exception;
use FilesystemIterator;
use Grav\Common\Config\Config;
use Grav\Common\Grav;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RegexIterator;
Expand Down Expand Up @@ -84,9 +83,11 @@ class Assets

// Default values for pipeline settings
protected $css_minify = true;
protected $css_minify_old = false;
protected $css_minify_windows = false;
protected $css_rewrite = true;
protected $js_minify = true;
protected $js_minify_old = false;

// Arrays to hold assets that should NOT be pipelined
protected $css_no_pipeline = [];
Expand Down Expand Up @@ -159,6 +160,11 @@ public function config(array $config)
$this->css_minify = $config['css_minify'];
}

if (isset($config['css_minify_old'])) {
$this->css_minify_old = $config['css_minify_old'];
}


if (isset($config['css_minify_windows'])) {
$this->css_minify_windows = $config['css_minify_windows'];
}
Expand All @@ -172,6 +178,10 @@ public function config(array $config)
$this->js_minify = $config['js_minify'];
}

if (isset($config['js_minify_old'])) {
$this->js_minify_old = $config['js_minify_old'];
}

// Set collections
if (isset($config['collections']) && is_array($config['collections'])) {
$this->collections = $config['collections'];
Expand Down Expand Up @@ -730,8 +740,14 @@ protected function pipelineCss($group = 'head')
// Concatenate files
$buffer = $this->gatherLinks($temp_css, CSS_ASSET);
if ($css_minify) {
$min = new \CSSmin();
$buffer = $min->run($buffer);
if ($this->css_minify_old) {
$min = new \CSSmin();
$buffer = $min->run($buffer);
} else {
$minifier = new \MatthiasMullie\Minify\CSS();
$minifier->add($buffer);
$buffer = $minifier->minify();
}
}

// Write file
Expand Down Expand Up @@ -804,7 +820,13 @@ protected function pipelineJs($group = 'head')
// Concatenate files
$buffer = $this->gatherLinks($temp_js, JS_ASSET);
if ($this->js_minify) {
$buffer = \JSMin::minify($buffer);
if ($this->js_minify_old) {
$buffer = \JSMin::minify($buffer);
} else {
$minifier = new \MatthiasMullie\Minify\JS();
$minifier->add($buffer);
$buffer = $minifier->minify();
}
}

// Write file
Expand Down
5 changes: 5 additions & 0 deletions system/src/Grav/Console/Cli/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class CleanCommand extends Command
'vendor/ircmaxell/password-compat/version-test.php',
'vendor/ircmaxell/password-compat/.travis.yml',
'vendor/ircmaxell/password-compat/test',
'vendor/matthiasmullie/minify/bin',
'vendor/matthiasmullie/minify/composer.json',
'vendor/matthiasmullie/minify/CONTRIBUTING.md',
'vendor/matthiasmullie/minify/data',
'vendor/matthiasmullie/path-converter/composer.json',
'vendor/maximebf/debugbar/bower.json',
'vendor/maximebf/debugbar/composer.json',
'vendor/maximebf/debugbar/.bowerrc',
Expand Down

0 comments on commit a24b7fa

Please sign in to comment.