Intranet 站点的积极缓存与 Javascript 文件组合

发布于 2024-12-16 13:20:31 字数 340 浏览 7 评论 0原文

我正在致力于提高公司 Intranet 页面的页面性能。我们希望(动态)合并我们的 javascript 文件并将它们缓存 30 多天。每个人登录后都会启动该页面。

我的一位同事问,如果我们已经将 JS 文件缓存了一个月,是否值得花时间合并这些文件。他对是否要同时执行这两项操作犹豫不决,因为组合工具是服务器端的,不能在我们的桌面上运行,需要一种有点古怪的解决方法。

我一直在做一些研究,我看到的大多数性能建议都是针对外部网站的。由于我们处于一个封闭的系统中,一旦每个人的缓存都已准备好,我们似乎不会从合并文件中获得太多好处。组合文件会给我们带来什么,而激进的缓存则不会呢?

如果这有什么区别的话,我们就使用 IE8。

I'm working on improving the page performance of my company's intranet page. We're looking to (dynamically) combine our javascript files as well as cache them for 30+ days. The page launches on login for everyone.

One of my coworkers asked if it's worth the time to combine the JS files if we're already caching them for a month. He's hesitant to do both because the combining tool is server side and doesn't run on our desktop, requiring a somewhat hacky workaround.

I've been doing some research and most of the recommendations for performance I've seen are for external sites. Since we're in a closed system it would seem like we wouldn't get much benefit from combining the files once everyone's cache is primed. What would combining the files buy us that aggressive caching wouldn't?

We're on IE8 if that makes any difference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

风为裳 2024-12-23 13:20:31

拥有多个 JavaScript 文件最显着的影响是渲染页面所需的时间。每个脚本标记都是单独处理的,并会增加整个渲染过程的时间。

可以在这里找到一个很好的答案@多个与单个脚本标签

如果我们正在谈论大量脚本,那么您可能会看到渲染时间有所改善;如果只有两个或三个文件,那么一旦文件被缓存,它可能不会带来明显的差异。

我建议在这两种情况下测试页面渲染时间,看看您在您的情况下看到了多少改进,并根据该信息做出决定。

作为一个有用的示例,以下是来自 Xpedite< 的一些统计信息/a> (我不久前创建的运行时缩小工具);请注意从加载到准备组合脚本与未组合脚本之间的时间差异。

The most notable impact with having multiple JavaScript files is the time required to render the page. Each script tag is processed separately and adds time to the overall render process.

A pretty good answer can be found here @ multiple versus single script tags

If we are talking a large number of scripts then you may see an improvement in render time; if it is just two or three files then it likely won't bring abount a noticable difference once the files have been cached.

I would suggest testing the page render time in both cases and see how much improvement you see in your case and decide based on that information.

As a useful example, here are some stats from Xpedite (runtime minification tool I created a while back); note the difference in time from load to ready for combined vs uncombined scripts.

墟烟 2024-12-23 13:20:31
  1. 将所有 JavaScript 文件合并到一个大文件中(从而最大限度地减少对服务器的请求数量),并将其名称设置为“application_234234.js”之类的名称;该数字代表您上次更改文件的时间,并将帮助浏览器知道这是一个新文件(因此当您更改它时不会缓存)。
  2. 添加一个 Expires 或一个 Cache-Control 标头(将其设置为非常遥远的未来)。由于每次修改文件名都会改变,因此您不必担心。
  3. 最后也是最重要的一点,压缩并 gzip JavaScript 文件。

这些是一些重要的建议,但要了解有关最佳实践的更多信息,请访问:http://developer.yahoo.com /性能/rules.html

  1. Combine all your JavaScript files into a single big file (thus minimizing the number of requests made to the server), and set its name to something like "application_234234.js"; the number represents the last time you have changed the file and will help the browser know it's a new file (thus no cache when you change it).
  2. Add an Expires or a Cache-Control Header (set it really far into the future). Since the file name will change each time you'll modify it, you don't have to worry.
  3. Last and not least, compress and gzip the JavaScript file.

These are some important advices, but learn more about best practices on: http://developer.yahoo.com/performance/rules.html

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