| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPCoder\Optimization; |
| 4 |
|
| 5 |
// Exit if accessed directly. |
| 6 |
defined( 'ABSPATH' ) || exit; |
| 7 |
|
| 8 |
class CSSMinifier { |
| 9 |
|
| 10 |
public static function minify($css): string { |
| 11 |
$css = preg_replace('/\/\*(.*?)\*\//s', '', $css); // Remove comments |
| 12 |
$css = preg_replace('/\s+/', ' ', $css); // Remove whitespace |
| 13 |
$css = preg_replace('/;\s*/', ';', $css); // Remove spaces after semicolons |
| 14 |
$css = preg_replace('/: /', ':', $css); // Remove spaces after colons |
| 15 |
$css = preg_replace('/\s{2,}/', ' ', $css); // Remove multiple spaces |
| 16 |
return trim($css); |
| 17 |
} |
| 18 |
|
| 19 |
} |