From d060d1c918c1340ec92363ce13247d3fb60069e8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 27 Jun 2013 18:34:10 +0200 Subject: [PATCH] Simple stylesheet compression to save ~10% file size --- .../lib/system/style/StyleCompiler.class.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index 4f2ec4ba30..fa5c052a63 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -183,6 +183,28 @@ class StyleCompiler extends SingletonFactory { $content = $callback($content); + // compress stylesheet + $lines = explode("\n", $content); + $content = $lines[0] . "\n" . $lines[1] . "\n"; + for ($i = 2, $length = count($lines); $i < $length; $i++) { + $line = trim($lines[$i]); + $content .= $line; + + switch (substr($line, -1)) { + case ',': + $content .= ' '; + break; + + case '}': + $content .= "\n"; + break; + } + + if (substr($line, 0, 6) == '@media') { + $content .= "\n"; + } + } + // write stylesheet file_put_contents($filename.'.css', $content); -- 2.20.1