网站文件缓存?

发布于 2024-08-31 03:56:36 字数 143 浏览 4 评论 0原文

我想知道某些文件(如 css、html 和 js)需要通过 .htaccess 设置缓存多长时间,以及为什么每种文件类型的时间设置不同?

在几个例子中,我看到有人缓存 html 10 分钟,js 缓存一个月,图像缓存一年。

I want to know how long certain files like css, html and js are desirable to be cached by .htaccess setting and why different time setting for each file type?

In few examples i saw that someone cache html for 10 mins, js for a month and imagery for a year.

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

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

发布评论

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

评论(1

养猫人 2024-09-07 03:56:36

我认为这取决于资源更新的频率。您的 HTML 内容可能是动态的,因此您无法长时间缓存它。否则,访问者会在长时间延迟后看到更改。

另一方面,图片很少更新,因此可以设置更长的缓存时间。

JavaScript 文件经常会针对新功能或错误修复进行更新。也许您可以使用此文件的版本号 (core.js?v=12323),以便您可以更改 HTML 内容中的版本号,以便访问者刷新它们。这样您也可以将它们缓存更长时间。

I think it depends how often a resource is updated. You HTML content is probably dynamic, so you can't cache it for a long time. Otherwise a visitor sees the changes after a long delay.

On the other side, pictures are rarely updated, so you can set longer cache time.

The JavaScript files are often updated for new features or bugfixes. Maybe you can use a version number for this files (core.js?v=12323) so that you can change the number in your HTML content to get them refreshed by a visitor. This way you can cache them for a longer time as well.

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