开发者

What Are The Cons (Ill-Effects) Of HTML, JavaScript and CSS Minification?

开发者 https://www.devze.com 2023-04-04 11:54 出处:网络
First, I see that Google suggests minifying everything - - HTML, JS and CSS to increase performance. But I doubt it does only good, and no bad开发者_StackOverflow社区; especially because many of the

First, I see that Google suggests minifying everything - - HTML, JS and CSS to increase performance.

But I doubt it does only good, and no bad开发者_StackOverflow社区; especially because many of the popular websites haven't enabled at least HTML minification (and some haven't even enabled JS and CSS minification as well).

So, can someone knowledgeable, please enlighten me off the ill-effects / cons of enabling the following on a website:

  • HTML minification
  • JS minification
  • CSS minification

  • for example, I heard that HTML minification could cause issues with Google analytics and Adsense (or any ad) code in the page. Is it true?


If done right, minification can be completely without side effects. The thing is, it’s not that easy to get things right.

For example, Google’s JS compiler, Closure, generally works fine but breaks more complex scripts. Always a tradeoff, better compression at the cost of less compatibility, or the other way around.

Also, by enabling gzip, you achieve somewhat more compression than minification, all without touching your code. This burns server CPU.

Bottomline is, if you’re not sure you need minificaton — you probably don’t.


  • Deployment will be more complex and error-prone. Where you could previously just upload your whole code, you know have to make certain to compilers.
  • Development becomes more complex; developers will probably install the minification tools.
  • Debugging becomes more complex, you know have to use a utility to find the original line. Of course.
  • Minifiers could have errors and introduce errornous code (that of course could cause various issues).

For large software projects, the first three criteria are all but irrelevant, and bugs in minifiers can be mitigated by careful (automated) testing. For a small/personal project, you probably don't need minification unless bandwidth or website performance is an issue.

0

精彩评论

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

关注公众号