views:

598

answers:

6

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?

+3  A: 

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.

Pekka
+3  A: 

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.

Michael Williamson
best answer imo.
Alexandre C.
+14  A: 

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

Dominic Rodger
note that most often minify css or javascript include merging files which could not be done with html file for the reasons you give.
Boris Guéry
A: 

usually html that is sent to the user is generated with a server technology (ASP.NET,PHP, RoR...) and trying to minify something dynamic on every request can decrease the servers performance and it will only decrease the size of html by a couple of bytes

Yassir
A: 

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.

Nick Craver
A: 

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.

Josh Stodola