HTML、JavaScript 和 CSS 缩小有哪些缺点(不良影响)?
首先,我看到 Google 建议缩小所有内容 - HTML、JS 和 CSS 以提高性能。
但我怀疑它只会带来好处,不会带来坏处;特别是因为许多流行网站至少没有启用 HTML 缩小(有些甚至还没有启用 JS 和 CSS 缩小)。
因此,有知识的人可以告诉我在网站上启用以下功能的不良影响/缺点:
- HTML 缩小
- JS 缩小
CSS 缩小
例如,我听说 HTML 缩小可能会导致页面中的 Google 分析和 Adsense(或任何广告)代码出现问题。这是真的吗?
First, I see that Google suggests minifying everything - - HTML, JS and CSS to increase performance.
But I doubt it does only good, and no bad; especially because many of the popular websites haven't enabled at least HTML minification (and some haven't even enabled JS and CSS minification as well).
So, can someone knowledgeable, please enlighten me off the ill-effects / cons of enabling the following on a website:
- HTML minification
- JS minification
CSS minification
for example, I heard that HTML minification could cause issues with Google analytics and Adsense (or any ad) code in the page. Is it true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果做得正确,缩小可以完全没有副作用。问题是,要把事情做好并不那么容易。
例如,Google 的 JS 编译器 Closure 通常工作正常,但会破坏更复杂的脚本。总是需要权衡,更好的压缩以较低的兼容性为代价,反之亦然。
此外,通过启用 gzip,您可以实现比缩小更多的压缩,而所有这些都无需触及您的代码。这会烧毁服务器CPU。
最重要的是,如果您不确定是否需要缩小,那么您可能不需要。
If done right, minification can be completely without side effects. The thing is, it’s not that easy to get things right.
For example, Google’s JS compiler, Closure, generally works fine but breaks more complex scripts. Always a tradeoff, better compression at the cost of less compatibility, or the other way around.
Also, by enabling gzip, you achieve somewhat more compression than minification, all without touching your code. This burns server CPU.
Bottomline is, if you’re not sure you need minificaton — you probably don’t.
对于大型软件项目,前三个标准几乎无关紧要,并且可以通过仔细(自动化)测试来减轻缩小器中的错误。对于小型/个人项目,您可能不需要缩小,除非带宽或网站性能是一个问题。
For large software projects, the first three criteria are all but irrelevant, and bugs in minifiers can be mitigated by careful (automated) testing. For a small/personal project, you probably don't need minification unless bandwidth or website performance is an issue.