JavaScript 提取器:从库中提取网页中真正使用的函数/对象
这是与以下问题相关的孪生问题:
JavaScript stripper:删除网页中未使用的函数/对象
为了最大限度地提高解决问题的机会,我以相反的方式提出问题:
我的所有网页都使用 JavaScript库,为了提高网页的性能,我只包含每个页面库中所需的函数/对象。 我正在寻找一个可以自动进行智能提取的工具。
谢谢你的帮助,
于
This is a twin question to the following:
JavaScript stripper: remove functions/objects that are not used in a web page
To maximize my chance of getting my problem solved, I'm asking the question in opposite manner:
All of my web pages use a JavaScript library, to improve the performance of my web pages, I'd only include only the needed functions/objects from the library for each page. I'm looking for a tool that can do the intelligent extraction automatically.
Thanks for your help,
Yu
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定这是一个真正的问题吗?
我之所以问这个问题,是因为在每个页面上包含相同的、完整的 JavaScript 库应该不是问题。 事实上,为每个页面提供不同版本的库实际上会减慢您的网站速度。
原因是 JavaScript 被浏览器缓存了。 如果每个页面都请求相同的库,则他们不必在第一次之后就必须从您的网站实际下载该库。
关键是确保您的库发送时带有 HTTP
Expires
标头,告诉浏览器缓存响应。Are you sure this is a real problem?
The reason I ask is because it should not be a problem to include the same, full JavaScript library on every page. In fact, serving different versions of the library to each page will actually slow down your site.
The reason is that JavaScript is cached by the browser. If each page requests the same library, they will not have to actually download the library from your site after the first time.
The key is to make sure your library is sent with an HTTP
Expires
header that tells the browser to cache the response.你做错了。 每个页面使用单独版本的 javascript 库是一个坏主意,因为该库不会被缓存,而是会为每个页面单独获取。 您最好缩小、连接和 GZIP 脚本,并为所有页面提供完全相同的脚本文件。
但是,如果您需要知道实际运行了哪些线路,则可以使用 JSCoverage 找到。
You are doing it wrong. Separate versions of a javascript library for each page is a bad idea since the library won't be cached but fetched separatly for each page. You're better off minifying, concatinating and GZIP your scripts and serve the exact same script file for all pages.
However, if you need to know what lines are actually run, you can probably find out using JSCoverage.