开发者

Is there something like jsmin for css? [duplicate]

This question already has answers here: 开发者_运维技巧 Closed 11 years ago.

Possible Duplicate:

Any recommendations for a CSS minifier?

JsMin is a compression and combination executable for javascript files. Is there something like that for CSS files?


Google #1 result for CSS compression: http://www.refresh-sf.com/yui/


CSS cannot be minified in the same way that JavaScript can. You can replace variables such as lastItemRead with names like a, but in CSS you cannot replace selectors like .lastItemRead with shorter selectors (not without crawling through and rewriting your entire site).

That being said, you can remove white-space and comments from CSS files. There are several tools that exist for doing this - the YUI Compressor is a popular option from Yahoo!.

There's a lot you yourself can do also to keep your CSS files lightweight. Remove unused selectors, reduce redundancy, and try to join many rules:

background-color:red;
background-image:url(stars.png);
background-position:center center;
background-repeat:no-repeat;

Is a bit verbose; better to write it as:

background:red url(stars.png) center center no-repeat;

Saves a tremendous amount of space. Another thing to look out for is adding unnecessary characters to rules. For instance, when you are setting paddings and margins, there's no need to add a unit after your 0 values:

margin:0px 10px; /* 0px should be 0 */

A lot of this stuff can be fleshed out by using a great tool like the CSSLint, online at http://csslint.net/. Warning: CSSLint will hurt your feelings!


Yes, you can visit this :

http://lesscss.org/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜