3

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; 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?

1
  • No one has answered this: I heard that HTML minification could cause issues with Google analytics and Adsense (or any ad) code in the page. Is it true? Commented Sep 14, 2011 at 1:14

2 Answers 2

3

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.

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

5 Comments

[1] I have tested my website on all major browsers (IE6 and IE7 too!) and it looks and works almost exactly the same in all of them - - no visible issues. So, I guess, I need not worry about minifying right? [2] I heard that HTML minification could cause issues with Google analytics and Adsense (or any ad) code in the page. Is it true?
As for (1), yup, the only things that matters is that you tested it and it works. An ad code is (usually) a JavaScript snippet, so if you don’t mess it up it should work fine, too.
Minifying isn't about "does it work?" so much as "does it perform well and does it scale?". You need it to work, first, and you need minification not to break it, but then you need to minimize network bandwidth, CPU load, etc. gzip reduces bandwidth at the cost of CPU, but minification reduces both. That said, I haven't had to minify because I'm getting good performance and scalability without it (so far)
@ayanami : are there any guide lines to minify file without side effects
@surya Just use UglifyJS 3 with default settings, works like a charm.
0
  • 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.

3 Comments

[1] I have tested my website on all major browsers (IE6 and IE7 too!) and it looks and works almost exactly the same in all of them - - no visible issues. So, I guess, I need not worry about minifying right? [2] I heard that HTML minification could cause issues with Google analytics and Adsense (or any ad) code in the page. Is it true?
@Aahan: About your point 1, cross-browser testing and minification are two unrelated issues aren't they? If you've tested and it works: good. If it all seems to be running too slowly or taking too much bandwidth then minification is one option to look at that might help.
@Ahan [2] No, unless the minifier is buggy.

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.