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

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).


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.


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.


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.