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, Ed, biapar, Willr, Ingo, swaiba

Minify CSS?

Go to End

3 Posts   2116 Views


Community Member, 79 Posts

26 June 2012 at 6:02am

Does anyone know if SS ever incorporated an easy way to minify css? I know the combine js method automatically minifies the js, but I haven't been able to find a way to make SS minify css. It's not a big deal to minify on my own, just thought maybe I was missing yet another cool built in action.




Community Member, 72 Posts

26 June 2012 at 6:27am

Edited: 26/06/2012 7:30am

to minify the css, its almost exactly like minifying the js.

Throw your css files into the array, then have the following line:

Requirements::combine_files('combinedCSS.css', $cssArray);

I don't add my IE style sheets though, because I call them like this:

Requirements::insertHeadTags('<!--[if IE 6]><style type="text/css">@import url(' . $themeFolder . '/css/ie6.css);</style><![endif]-->');

Edit: Almost forgot... Silverstripe will only minify your js and css if you are in "Live" mode.


Community Member, 79 Posts

26 June 2012 at 7:42am

Edited: 26/06/2012 7:53am

That's close to the same code I've been using. I had $CSSFiles instead of $cssArray. It definitely combines the files but doesn't seem to be stripping anything like comments or moving the code so that it is inline. The javascript looks like a min file - no white space, no comments, etc..., but the css just combines whichever files I am combining. Kind of quirky...perhaps it's because I am still using an older version of SS (2.4.5) I just tried the $cssArray but it seems to have made the page load slower so I went back to the original code.

I did know about the live mode, but thanks for the heads up. I'm sure someone reading this would probably be banging their head against the wall if they tried it in dev...

Thanks for your input!