javascript - 为什么 Google Page Speed Insights 说要缩小 JS
问题描述
我运行了 Google Page Speed Insights,他们的主要建议是缩小js
文件,节省超过 70%(准确地说是从 423 KB 到 312 KB),这太疯狂了。
但是文件被缩小了!我错过了什么?
资源:
PS我已经解决了关于SO的其他类似问题,但都与我的问题不相似。
解决方案
我建议浏览您的缩小文件并寻找人类可读的 JS 令牌。
据我所知,测试主要是看 JS 令牌长度。
/**
* @fileOverview Estimates minification savings by determining the ratio of parseable JS tokens to the
* length of the entire string. Though simple, this method is quite accurate at identifying whether
* a script was already minified and offers a relatively conservative minification estimate (our two
* primary goals).
*
* This audit only examines scripts that were independent network requests and not inlined or eval'd.
*
* See https://github.com/GoogleChrome/lighthouse/pull/3950#issue-277887798 for stats on accuracy.
*/
如果您在缩小文件中看到人类可读的标记,请尝试查看您的缩小器设置,看看是否有可以切换的选项来消除这些标记。
如果没有设置可以消除它们,请尝试确定它们的来源以及它们与其他成功缩小的令牌有何不同。罪魁祸首可能是编码模式、框架或转译器。
注意:源代码链接自他们的帮助页面(https://web.dev/unminified-javascript/)
推荐阅读
- javascript - Mobx-state-tree:如何将 AnonymousModel 重命名为商店名称
- mysql - 用户喜欢关系的表格设计
- python - Jupyter notebook 找不到包
- c# - 我正在投影 mongodb 文档本身,但一个有效,另一个无效
- django - 带有 Huey 任务消费者的 Django:TestCase 方法触及真实数据库
- python - Pytorch 中的“unsqueeze”是做什么的?
- c# - WinForm App未将日志写入LinqPad中数据源时创建的文件
- google-apps-script - 尝试在没有 for 循环的范围内执行 setValue 操作(GoogleAppsScripts)
- c# - 协程在 WaitForSeconds 期间执行代码
- r - 从长格式数据帧构建节点和边