apache2 DirectoryIndex 更改不会绕过缓存索引

apache2 DirectoryIndex change does not bypass cached index

我正在努力确保我网站的访问者看到的是最新版本。为此,我编写了一个脚本来重命名适当的文件和请求,以便它们在构建时附加一个新的版本号。这包括索引文件,我们称之为 index-v123.html.

我已经上传了这个构建源并通过包含

将我的 apache2 服务器指向新的索引文件
DirectoryIndex index-v123.html

在我的 apache2.conf 中。我已经重新启动它,当以 chrome 隐身模式或硬刷新查看网站时,我可以看到所有新文件都已加载并且网站按预期工作。

我的问题是,在我的普通浏览器中,当我访问 URL 时,我仍然加载 index.html 的缓存版本。显然更改 DirectoryIndex 并没有像我希望的那样说服客户转到新的索引文件...

那么我可以做些什么来实现这一目标吗?

(也可能相关:我是 运行 一个使用 Polymer 2.0 的渐进式网络应用程序,service-worker.jspolymer build 自动构建。)

这原来是一个服务工作者问题:service-worker.js 被缓存在客户端,因此提供了过时的内容,就好像客户端处于离线模式一样。只能通过取消注册工人来更新。解决方案是在 apache2 服务器端的 service worker 上实现 max-age=0

<Files index.html|service-worker.js>
    FileETag None
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</Files>

很惊讶这并没有在某处的聚合物 build/production 文档中更好地突出显示。作为参考,在服务人员的 google primer 中它说:

The caching headers on the service worker script are respected (up to 24 hours) when fetching updates. We're going to make this opt-in behaviour, as it catches people out. You probably want a max-age of 0 on your service worker script.