Jump to:

23358 Posts in 18039 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Minify CSS?

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

Page: 1
Go to End
Author Topic: 792 Views
  • honeybunny
    Avatar
    Community Member
    79 Posts

    Minify CSS? Link to this post

    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.

    Thanks!

    HB

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: Minify CSS? Link to this post

    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.

  • honeybunny
    Avatar
    Community Member
    79 Posts

    Re: Minify CSS? Link to this post

    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!

    792 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.