Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

CSS Minify fast fix


8 Posts   2131 Views


6 July 2010 at 9:24am (Last edited: 6 July 2010 9:28am), Community Member, 81 Posts

Code is need some optimisations, but I needed to do it fast
Well ok, instruction:
1. Download minify from
2. Unpack Compressor.php from /min/lib/Minify/CSS/ to sapphire/thirdparty/minify
3. Open sapphire/core/Requirements.php
4. Find and replace foreach on 1000th line with that =))

foreach(array_diff($fileList, $this->blocked) as $file) {
            $fileContent = file_get_contents($base . $file);
            // if we have a javascript file and jsmin is enabled, minify the content
            $isJS = stripos($file, '.js');
            if($isJS && $this->combine_js_with_jsmin) {
               $fileContent = JSMin::minify($fileContent);
            } else {
               $isCSS = stripos($file, '.css');
               if($isCSS) {
                  $fileContent = Minify_CSS_Compressor::process($fileContent);
            // write a header comment for each file for easier identification and debugging
            // also the semicolon between each file is required for jQuery to be combinable properly
            $combinedData .= "/****** FILE: $file *****/\n" . $fileContent . "\n".($isJS ? ';' : '')."\n";


1. replace $isCSS && $isJS with one property
2. add $this->combine_css_with_minify property
3. add minify option for all required css's (not only combined)
4. like 3rd, but for JS and JSmin


6 July 2010 at 10:43pm Community Member, 271 Posts

Note that 2.4 is using compressed javascript files for combined files.

You can do the same for CSS without touching core files.

See this method in Page::init();

You have to set the site in live mode to use combined files.....


7 July 2010 at 5:57pm Community Member, 81 Posts

jsmin doesn't minify css and google minify deletes all comments, spaces, new lines and etc in css files


12 July 2010 at 9:59pm Community Member, 271 Posts

See this part:

if(file_exists(Director::baseFolder() . '/' .$combinepath.'/combined.css')){
            $bf = file_get_contents(Director::baseFolder() . '/' .$combinepath.'/combined.css');
            $bf = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $bf);
            $bf = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $bf);
            $fh = fopen(Director::baseFolder() . '/' .$combinepath.'/combined.css', 'w');
            fwrite($fh, $bf);


13 July 2010 at 10:44am Community Member, 181 Posts

Great stuff.

I was looking for a way of doing just this and came across minify.

Think I'll use a combination of both ideas, create a class based on minify and call it using Martijn's method. That way I get the best of both worlds; an external library to do the work and no need to edit core files.




13 July 2010 at 4:39pm Forum Moderator, 5511 Posts

Tonyair I think this would be good to have in core. I think it might have an older version which needs upgrading anyway and being able to combine CSS as well as JS by default would be good.

If you can get the contents of this thread together and submit a patch it would be good to include. See for submission guidelines.


3 August 2010 at 8:31am Community Member, 51 Posts

Of note;

There's a nice project in PHP Minify that handles CSS & JS minification & combining, and support some "advanced" features like skipping files w/ a .min.(css|js) extension (already minified files) while processing as well as security & group definitions.

Project URL is:

It would be great to see SS combine_files on par w/ this project, or perhaps to utilize it instead.


21 September 2010 at 1:22am Community Member, 81 Posts

Willr, i will be glad, but I made too many changes so I can update my version only manually.
For example i changed structure of SS I believe that in public_html should be placed only public files like css, images, javascript, swf, assets and index.php all other files should be placed in the upper directory