Why do many sites minify CSS and JavaScript but not HTML?

JavascriptHtmlCssOptimizationMinify

Javascript Problem Overview


> Possible Duplicate:
> Why minify assets and not the markup?

I have seen a lot of sites using minified CSS and JavaScript to increase website response time but I have never seen any sites use minified HTML. Why would you not want your HTML to be minified?

Javascript Solutions


Solution 1 - Javascript

Because if you're doing things properly you're serving HTML gzipped anyway, so the low-hanging fruit of HTML minification - whitespace - isn't all that relevant. There aren't lots of easy targets (e.g. variable names) for minification in HTML, which are present in CSS and JavaScript. Much of the content of HTML is the actual content of the page, which probably can't be minified (and, as others have pointed out, will almost certainly vary more frequently than your CSS or JS).

Solution 2 - Javascript

I'd guess that most sites have static CSS and Javascript. This means they can be minified just once whenever they are updated. On the other hand, HTML tends to be dynamically generated, which means it would have to be minified on every page request, which is considerably more expensive than minifying static CSS and Javascript files.

Solution 3 - Javascript

I don't think there is that much room for minification in HTML: You can remove white spaces and line breaks, but essentially, that's about it without actually getting into the page's structure.

JS minification can shorten variable and function names, probably the biggest net profit in terms of saved space. With its fixed set of tags, HTML does not provide that possibility.

The option of gzipping HTML probably eliminates much of the need to minify anyway, especially as it is usually enabled for HTML, while it (unnecessarily) not always is for the CSS and JS file types.

Solution 4 - Javascript

Primarily because Javascript files and CSS stylesheets are often static files that will not change upon deployment. Markup, on the other hand, is often generated on the fly (with database-driven web apps, at least), and the number of "pages" is usually large and dynamic, which makes the benefits of minification more work than it's worth.

Solution 5 - Javascript

Html content being gzipped takes care of most of the compression, minifying on top of that wouldn't accomplish much or save a great deal of bandwidth.

Javascript you can minify as part of the build, the only way this would happen with the entire HTML content would be to minify every piece (what if it's generated?) or to have it minified the whole time (nightmare to work on?)

It's cost vs benefit, cost: marginal bandwidth, benefit: easier to work on, easier to generate, easier to debug, pretty in my source view window.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJosh CurrenView Question on Stackoverflow
Solution 1 - JavascriptDominic RodgerView Answer on Stackoverflow
Solution 2 - JavascriptMichael WilliamsonView Answer on Stackoverflow
Solution 3 - JavascriptPekkaView Answer on Stackoverflow
Solution 4 - JavascriptJosh StodolaView Answer on Stackoverflow
Solution 5 - JavascriptNick CraverView Answer on Stackoverflow