6

I've looked at half a dozen CSS optimisers out there. What I'm looking for is one that will turn:

background-image: url(../images/background.png);
background-repeat: repeat-x;
background-color: #c0c0c0;

Into the single background property:

background: #c0c0c0 url(../images/background.png) repeat-x;

How can I do this? Do I have to do it by hand?

1
  • good luck - that's more like refactoring than minification Commented Feb 23, 2011 at 23:28

2 Answers 2

16

Try http://www.cssoptimiser.com/

Input:

body {
    background-image: url(../images/background.png);
    background-repeat: repeat-x;
    background-color: #c0c0c0;
}

(I ticked "Do not remove line breaks")

Output:

body {
    background:#c0c0c0 url(../images/background.png) repeat-x
}

Note that it also optimised away the space - you asked for background:<space>#... :)

There may be other/better tools which can do this, but that site does fulfill your wish.

Sign up to request clarification or add additional context in comments.

Comments

4

Make sure you also have gzip enabled on your server (or some other form of compression for text files).

1 Comment

A good point. You'll probably save much more from HTTP compression than CSS optimisation. A pedantic tip to squeeze every last byte out of your CSS size (if you're using HTTP compression) - use lowercase colours: don't use #CFCFCF, use instead #cfcfcf - that way the compression ratio will be slightly higher because you're more likely to have the characters c and f than C and F in your file, because everyone uses lowercase declarations, like color: red.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.