What is the best method to reduce the size of my Javascript and CSS files?

后端 未结 18 1033
礼貌的吻别
礼貌的吻别 2020-11-30 04:16

When working with large and/or many Javascript and CSS files, what\'s the best way to reduce the file sizes?

18条回答
  •  臣服心动
    2020-11-30 04:46

    CssTidy is the best CSS optimizer of which I am aware. It (configurably) strips comments, eliminates whitespaces, rewrites to use the many shorthand rules nickf mentioned, etc. Compressing the result helps too, as others have mentioned.

    The compression ratio can be fairly dramatic, and it frees you to comment your CSS extensively without worrying about the file size.

    Unfortunately, this level of preprocessing interacts with some of the popular "css hacks" in unpredictable (or predictable but undesired) ways. Some work, some don't, and some require configuration settings which reduce the level of compression for other things (especially comments).

提交回复
热议问题