我有一个用 PHP 编写的 Web 应用程序,我使用 header() 函数生成 header 。
问题是,当我更改我的应用程序的 javascript 代码时,在客户端,旧的 javascript 将不会执行,因为缓存到客户端浏览器。
如何自动执行 header 过期过程?我认为这一定是比每次修改 javascript 代码时都修改该函数更好的方法。
最佳答案
唯一的防弹解决方案是更改服务器端资源的文件名:
来自:雅虎的 Best Practices for Speeding Up Your Web Site :
Keep in mind, if you use a far future Expires header you have to change the component's filename whenever the component changes. At Yahoo! we often make this step part of the build process: a version number is embedded in the component's filename[...]
当然这个过程必须是自动化的。我们将 JavaScript 文件内容哈希附加到文件名中。
关于javascript - 自动http过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7412331/