HTML、JavaScript 和 CSS 缩小有哪些缺点(不良影响)?

发布于 2024-12-04 13:42:11 字数 318 浏览 0 评论 0原文

首先,我看到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-12-11 13:42:11

如果做得正确,缩小可以完全没有副作用。问题是,要把事情做好并不那么容易。

例如,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.

尸血腥色 2024-12-11 13:42:11
  • 部署将更加复杂且容易出错。以前您可以上传整个代码,但您知道必须向编译器保证。
  • 开发变得更加复杂;开发人员可能会安装缩小工具。
  • 调试变得更加复杂,您知道必须使用实用程序来查找原始行。当然。
  • 压缩器可能会出现错误并引入错误代码(这当然可能会导致各种问题)。

对于大型软件项目,前三个标准几乎无关紧要,并且可以通过仔细(自动化)测试来减轻缩小器中的错误。对于小型/个人项目,您可能不需要缩小,除非带宽或网站性能是一个问题。

  • Deployment will be more complex and error-prone. Where you could previously just upload your whole code, you know have to make certain to compilers.
  • Development becomes more complex; developers will probably install the minification tools.
  • Debugging becomes more complex, you know have to use a utility to find the original line. Of course.
  • Minifiers could have errors and introduce errornous code (that of course could cause various issues).

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文