CSS Mimimize or Not?

I can see it now the yeas and nays here in a tug a war but I had to ask anyway. :thought_balloon:

Basically while learning I have looked at a lot of pages of information. Some say minimize CSS always, some say only after the file gets over a certain size and others say minimizing is used mostly to hide bad code.

What do you all think?

I’m all for lightening the load the user has to consume, no matter how small the file may be. Coming in the other direction though, it may not be much of an impact for the user to reduce things by a couple of Kb, but for those paying the hosting bill, all those individual “couple of Kbs” adds up, especially if you get a lot of traffic to your site. On the other hand, you may be able to save a lot more by optimising your images for example.

I say,
At the least keep a readable copy for yourself to work with.
if the file is significantly large enough to be causing bandwidth sluggishness, gzip it
if you are worried about squeezing every last bit of optimization, gzip it
if your CSS is so bad you don’t want others to see it, improve your skills or move on

3 Likes

For those unfamiliar with gzip’ping files (like me), this may be a useful link - https://www.feedthebot.com/pagespeed/enable-compression.html

4 Likes

Thanks chrisofarabia, somethings have been familiar to me for so long I forget that at one time I didn’t know.

A note about that article, and @dklynn would agree, if you know your Apache server has mod_gzip lose the "if"s in you htaccess. No need to check to see if it exists every HTTP request if you know that it does.
<ifModule mod_gzip.c>

If my code was bad I would not hide it. How else could you get feed back from people who actually care so you can improve?

Basically the conclusion I came to was if it makes the file smaller by 1 or 2 kb may not be worth it.

When you have thousands of visitors and you have to pay the bill, 1-2 Kb become 1000-2000 Kb… or 4000-8000 Kb… or more, depending on your success. while the price per MB may not be overwhelming, at the end of the day, it adds up.

But then, this is a case to do some maths and see if it is worth it or not

Minimize to your heart’s content AFTER the site is finished, and keep a copy of the non-minimized code handy in case you decide to modify the site or find a problem.

With minimized code, tools like Firebug will identify all of the CSS as being on line 1. Awkward to work with.

1 Like

Amen.

Thanks, Alan, for pointing out the error (server abuse) in the article.

Regards,

DK

1 Like

For my small file I have no plans to minimize, would save just 1kb and much of that can be saved by removing comments. I just wanted to see how the pro’s think.

I’m not a pro, I couldn’t give myself away… :wink:

TBH, I’d look into a CDN that most hosts have - Cloudfare. They provide minifying without you even doing anything. You get the server-caching + the minifying. All for free. That’s what I like taking advantage of. See if your hosts offers it. Well worth it.

How big would a css file be for you to consider wanting minimising it?

I do have my video on a CDN. Costs me get this a wopping sum of $0.13 per month.

Was trying to quote @Mittineague next about gzip. Never knew it existed my old host used a Windows server.

Gzipping reduces my pages around 70% which is great since I have 40% mobile traffic.

Thank you for that tip.

Now for a sitepoint question. When replying using an Android device how the heck can one get the highlite and quote to work better. It is hit or miss weather the quote box comes up or Android goes to copy mode. Even if the quote box comes up half the time it won’t click.

It’s the same on iPad. Sometimes it’s good, others, not so much

You can usually save tons more space by optimising your images and scripts than optimising your css. Just leaving out one image will provide better results than squeezing every ounce of CSS.

Just get your priorities right first before looking at css as the culprit. If you’ve done everything else (minified, concatanated scripts etc) then css squashing would be the last step in the process. For a small site that doesn’t have high traffic then optimising the css may not be worth it (unless you have over-cooked the css to start with).

4 Likes

I really have no big culprits so to speak just little ones. Yes I still need to reduce the image file size where I can even though most of the site out side the image gallery has only minimal images.

My next operation is using an image sprite for my links section to reduce http requests for those from 5 to 1. That comes after replacing the office computers with faster ones which are on the way and completing the upgrade to cat6. gigabit.

According to Google webmaster tools it is a good idea to min you css for page loading to be faster.

And it is. But it is also true that you could improve performance with another thousands little things that will have more effect than minimizing CSS. Every website is different

I recommend using either Grunt or Gulp to concatenate, minify and push a production build of your project to a “dist” folder that you can then host. That way you can keep all your comments and organized files, while still getting the benefits of being concatenated and minified for production/hosting.