问题
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?
回答1:
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).
回答2:
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.
回答3:
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.
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/2359484/why-do-many-sites-minify-css-and-javascript-but-not-html