How to hide JavaScript comments in the resulting HTML page? [closed]

我与影子孤独终老i 提交于 2019-12-11 09:49:42

问题


Is there a way to hide the JS comments on the resulting page source? The JS is generic...

Thanks!


回答1:


Sure. Just minify your javascript with a tool like JSMin: http://www.crockford.com/javascript/jsmin.html

Or UglifyJS: https://github.com/mishoo/UglifyJS/ Or Google Closure: https://developers.google.com/closure/

They all strip comments and excess whitespace. Some will even change your variable names in crazy ways to save bytes.

Or write your JS in a compile to JS language like coffee script http://coffeescript.org/ which strips out comments at compile time.



来源:https://stackoverflow.com/questions/11664884/how-to-hide-javascript-comments-in-the-resulting-html-page

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