YSlow 说我的 JavaScript 文件在合并 5 个文件并打包后不再缓存
我从 5 个正常人类可读的 JavaScript 文件开始 - 它们总共大约 10 KB。
使用 YSlow 后,我决定合并这 5 个文件并使用 Dean Edwards 的打包器打包它们。现在我有 1 个 4.5 KB 的文件。
当我重新运行 YSlow 时,它现在在“统计”下的已启动缓存中显示 JavaScript 文件,而以前(当我有单独的文件时)将缓存 5 个文件。
因此,我现在的 HTTP 请求减少了 4 个,但已准备好的缓存的总页面重量增加了 4.5 KB。
我做错了什么吗?
我仍然计划在我的 JavaScript 文件夹中放置一个远期到期日期标头,这样这个问题可能会消失,但我仍然有兴趣知道为什么它不会缓存 JavaScript 文件。
I started with 5 normal human-readable JavaScript files - they were around 10 KB in total.
After using YSlow, I decided to merge the 5 files and pack them using Dean Edwards' packer. Now I have 1 file that is 4.5 KB.
When I re-run YSlow, it is now showing the JavaScript file in the primed cache under 'statistics', where previously (when I had the separate files) the 5 files would have been cached.
So I now have 4 fewer HTTP requests but the total page weight for the primed cache is up by 4.5 KB.
Am I doing something wrong?
I am still planning to put a far-forward expiry date header on my JavaScript folder so this issue will likely disappear, but I'm still interested to know why it won't cache the JavaScript files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您根本没有做任何错事,您正在遵循所有基本的最佳实践。
当您从没有正确设置
expires
的网络服务器下载某些内容时(我认为是这种情况,因为您想修复该问题),预置的缓存将始终更高,因为 YSlow 认为浏览器需要即使它已缓存所有内容也可以下载它。这是因为缓存在下载时设置为过期,因为没有 Expires 标头。更新你的过期时间以拥有长期有效的过期时间肯定会解决你的问题。
I don't think you are doing anything wrong at all, you are following all basic best practices.
When you download something from a webserver that doesn't have
expires
set properly, which I assume is the case since you want to fix that, the primed cache will always be higher because YSlow thinks that the browser needs to download it even when it has cached everything.This is because the cache is set to expire when its downloaded it because there is not Expires header. Updating your expires to have a long living expires will definitely sort your issue out.