Optimize websites by removing code comments?

♀尐吖头ヾ 提交于 2020-01-14 03:03:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!