如何强制浏览器自动从服务器检索新页面而不是 return 缓存页面

How do I force browser to automatically retrieve fresh page from server rather than return cached page

有(本地)Web 应用程序,用户首次通过 Web 浏览器连接到服务器时,会显示带有许可协议的弹出窗口 windows。如果他们接受它,弹出窗口 window 将被隐藏,并且会向服务器发出 Aysnc 调用,以保留 EULA 已被接受的事实,并重新创建页面,以便不会显示任何弹出窗口 windows (如果他们拒绝 EULA,网络应用程序将退出)。

如果用户没有做任何其他重要的事情,那么麻烦,然后用户通过网络浏览器再次连接到服务器,浏览器只是 returns 缓存的网页而不是新创建的版本,所以显示了 Eula再次。

如果他们强制刷新,EULA 弹出窗口就会消失,但这对用户来说并不容易。那么我如何才能强制浏览器转到服务器以获取最新版本的页面而不是返回缓存的页面。

这是一个 html 问题,但知道我正在使用 Spark Framework,一个用于创建 Web 应用程序的 Java 框架可能有用。

Chrome: Windows:按住"ctrl"并点击刷新按钮 Mac:按住"shift"并点击刷新按钮

火狐: Windows:按住"ctrl"并按下"f5" Mac:按住"shift"并按下"f5"

这被称为 "hard refresh"。

所以我有一个适合我的解决方案。当用户点击 OK 按钮时,它已经调用了一个与服务器对话的 Javascript 函数,然后当它返回时它向现有页面添加了一条消息。

function eulaAccept()
    {
       var xhr = new XMLHttpRequest();
       xhr.open('POST', '/start.eulaaccept', true);
       xhr.setRequestHeader("Content-type", "text/plain");
       xhr.send("done");
       $('#eula').modal('hide')
       xhr.onreadystatechange = function() {
           if (this.readyState == 4 && this.status == 200)
           {
               alerts=document.getElementById("messages");
               var alert = document.createElement("div");
               var msg   = document.createTextNode("Thankyou for accepting the EULA");
               alert.className = "alert alert-info";
               alert.appendChild(msg);
               alerts.appendChild(alert);
           }
       };
    }

但是由于服务器重新创建了页面,我只需要添加 window.location.reload(true); 以在服务器返回后强制重新加载文件。

function eulaAccept()
    {
       var xhr = new XMLHttpRequest();
       xhr.open('POST', '/start.eulaaccept', true);
       xhr.setRequestHeader("Content-type", "text/plain");
       xhr.send("done");
       $('#eula').modal('hide')
       xhr.onreadystatechange = function() {
           if (this.readyState == 4 && this.status == 200)
           {
               window.location.reload(true);
           }
       };
    }

(我删除了这条消息,因为我认为没有必要)