问题
I wonder if there is any (noticeable) performance improvement when removing code comments from .php, .js, .css, .html, and similar files?
回答1:
Mostly not, modern CPU's are very fast... The most notable improvement is the speed in the download speeds. Strip out any unnecessary comments sent down the wire to the browser, minify CSS, JavaScript files, use CDN's etc.
回答2:
It depends how many comments there are.
In general though, most developers have a live version of all their code that is compressed- no whitespace outside of text formatting, no comments, etc. And an offline version that is developer-friendly with all the extra formatting and so on.
Another thing to note is with '//' style comments, they won't really hinder performance since the parser skips straight to the next line. With /**/ comments, the parsers has to keep reading all your comments until it encounters the closing */ so its ever-so-slightly more cpu intensive.
Paragraph 2 though, imo. :)
来源:https://stackoverflow.com/questions/6372243/optimize-websites-by-removing-code-comments