Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boost: Update CSS minification library #40956

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion projects/plugins/boost/.gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ vendor/automattic/** production-include
vendor/composer/** production-include
vendor/jetpack-autoloader/** production-include
vendor/tedivm/** production-include
vendor/tubalmartin/** production-include
vendor/matthiasmullie/** production-include
vendor/wikimedia/aho-corasick/** production-include

Expand Down
16 changes: 7 additions & 9 deletions projects/plugins/boost/app/lib/class-minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@

namespace Automattic\Jetpack_Boost\Lib;

use MatthiasMullie\Minify\CSS as CSSMinifier;
use MatthiasMullie\Minify\JS as JSMinifier;
use tubalmartin\CssMin\Minifier as CSSMinifier;

/**
* Class Minify
*/
class Minify {

/**
* @var CSSMinifier - Holds the CssMin\Minifier instance, for reuse on subsequent calls.
*/
private static $css_minifier;

/**
* Strips whitespace from JavaScript scripts.
*
Expand All @@ -44,10 +39,13 @@ public static function js( $js ) {
* Minifies the supplied CSS code, returning its minified form.
*/
public static function css( $css ) {
if ( ! self::$css_minifier ) {
self::$css_minifier = new CSSMinifier();
try {
$minifier = new CSSMinifier( $css );
$minified_css = $minifier->minify();
} catch ( \Exception $e ) {
return $css;
}

return self::$css_minifier->run( $css );
return $minified_css;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Concatenate CSS: Fixed cases where minification might cause a file to load slower.
3 changes: 1 addition & 2 deletions projects/plugins/boost/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"automattic/jetpack-status": "@dev",
"automattic/jetpack-sync": "@dev",
"automattic/jetpack-wp-js-data-sync": "@dev",
"matthiasmullie/minify": "^1.3",
"tubalmartin/cssmin": "^4.1"
"matthiasmullie/minify": "^1.3"
},
"require-dev": {
"automattic/jetpack-changelogger": "@dev",
Expand Down
59 changes: 1 addition & 58 deletions projects/plugins/boost/composer.lock

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

12 changes: 8 additions & 4 deletions projects/plugins/boost/serve-minified-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
if ( ! defined( 'JETPACK_BOOST_CONCAT_USE_WP' ) ) {
define( 'JETPACK_BOOST_CONCAT_USE_WP', false );

// Load CSSmin.
require_once __DIR__ . '/vendor/tubalmartin/cssmin/src/Colors.php';
require_once __DIR__ . '/vendor/tubalmartin/cssmin/src/Utils.php';
require_once __DIR__ . '/vendor/tubalmartin/cssmin/src/Minifier.php';
// Load minification library.
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/Exception.php';
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/Minify.php';
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/CSS.php';
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/JS.php';
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/Exceptions/BasicException.php';
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/Exceptions/FileImportException.php';
require_once __DIR__ . '/vendor/matthiasmullie/minify/src/Exceptions/IOException.php';
}

// Load minify library code.
Expand Down
Loading