IIS / AngularJS 单页应用程序 - 如何防止在应用程序中导航时单个 index.html 的页面缓存

IIS / AngularJS Single Page Application - How do I prevent page caching of a single index.html when navigating in app

我需要让我的应用程序 (SPA) 不缓存 index.html 跨页面导航操作。

我的应用程序有缓存破坏功能,但它仅在我更新(重新加载)时有效 index.html。

如何强制应用程序在我的应用程序内导航时不缓存 index.html 并在每次页面导航点击或操作时重新加载 index.html?

这是我现有的代码段 index.html 代码:

<!DOCTYPE html>
<html lang="en" manifest="sw.appcache">
  <head>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />

sw.appcache 文件内容

CACHE MANIFEST
NETWORK:
*

编辑:

我的 index.html 中的脚本标记的以下添加会在每次 url 更改时强制重新加载页面。

 window.onhashchange = function() {
        var parts = window.location.href.split("#");
        window.location.href = window.location.protocol + "//" + window.location.host + "?t=" + (new Date()).getTime() + "#" + parts[1];

      }

我在 PHP 中的经验是,您永远无法控制浏览器是否决定缓存您的页面,无论您使用什么花哨 headers。

最好的方法是用请求参数操作URL。

而不是http://example.com/mypage.html
使用:http://example.com/mypage.html?timestamp

其中时间戳在运行时动态生成,可以是随机数或您希望的任何 dynamically-unique 字符串。

防止浏览器缓存CSS、JS、图片等也是一个好技巧