简体   繁体   English

您托管的文件上的浏览器缓存

[英]Browser cache on files you host

I understand how to use version numbers and force the download of updated files on my own website but what can be done under this circumstance.....我了解如何使用版本号并在我自己的网站上强制下载更新的文件,但在这种情况下可以做什么.....

I have some small scripts i've written for public use , and i have about 200 different websites who link my js file on their website.我编写了一些供公众使用的小脚本,并且我有大约 200 个不同的网站将我的 js 文件链接到他们的网站上。 When i make an update to the file , i have to get them all to manually change the version number of the file so they and their users are re downloading the latest update.当我更新文件时,我必须让他们全部手动更改文件的版本号,以便他们和他们的用户重新下载最新的更新。

Is there anything i can do on my server , the host , that can force the other sites to redownload latest version without anything manual on their end of things ?我可以在我的服务器(主机)上做些什么来强制其他站点重新下载最新版本而无需任何手册?

There are 2 persistent problems in computing: Cache invalidation, naming things, and off-by-one errors.计算中有两个持续存在的问题:缓存失效、命名事物和一对一错误。

If you want clients to get new versions of a file without changing the name of the file then you simply have to lower the max-age you set in the caching headers so that they check more frequently and get the new version in a reasonable period of time.如果您希望客户端在不更改文件名的情况下获取文件的新版本,那么您只需降低在缓存标头中设置的max-age ,以便他们更频繁地检查并在合理的时间内获取新版本时间。

That's it.就是这样。 End of list.列表结束。

You can somewhat mitigate the effects of the increased request load by also implementing an ETag header that the client will send back on subsequent requests and can be used to detect if the resource is unchanged and optionally serve a 304 Not modified response.您可以通过实现客户端将在后续请求中发回的ETag标头,在一定程度上减轻请求负载增加的影响,并可用于检测资源是否未更改,并可选择提供304 Not modified响应。

However, depending on the cost of implementing and running ETag checks you might just want to re-serve the existing resource and be done with it.但是,根据实施和运行 ETag 检查的成本,您可能只想重新提供现有资源并完成它。

Or use a CDN which should handle all the ETag nonsense for you.或者使用应该为您处理所有 ETag 废话的 CDN。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM