From: Alexander Ebert Date: Thu, 27 Jun 2013 16:34:10 +0000 (+0200) Subject: Simple stylesheet compression to save ~10% file size X-Git-Tag: 2.0.0_Beta_5~120^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=d060d1c918c1340ec92363ce13247d3fb60069e8;p=GitHub%2FWoltLab%2FWCF.git Simple stylesheet compression to save ~10% file size --- 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);