【问题标题】:MEAN stack - Express - Page getting cached in IE 11 - 304 status codeMEAN stack - Express - 页面被缓存在 IE 11 - 304 状态码中
【发布时间】:2015-08-20 04:08:41
【问题描述】:

我正在使用 MEAN 堆栈来开发我的应用程序。该应用程序在 chrome 中运行良好,但是当在 IE 中打开页面时,当用户请求页面时,我从服务器获得 304 状态。因为这个缓存页面被返回给用户。

有趣的是,如果我打开 IE 开发者工具栏然后选择网络选项卡并记录各种请求,应用程序开始正常工作。我开始从服务器收到 200 响应。

到目前为止,我已经尝试过这个:app.disable('etag');

还有这个:

app.get('/*', function(req, res, next){ 
  res.setHeader('Last-Modified', (new Date()).toUTCString());
  next(); 
});

但是这两个选项都不适合我。

【问题讨论】:

标签: javascript express internet-explorer-11 mean.io http-status-code-304


【解决方案1】:

您是否尝试过设置此处描述的缓存标头:https://stackoverflow.com/a/9886945/442472。

Expires: Tue, 03 Jul 2001 06:00:00 GMT
Last-Modified: {now} GMT
Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate

我认为 etag 本身不允许浏览器了解服务器端所需的缓存策略应该是什么。 etags 实际上只是一种通过校验和识别服务器端资源的方法。

【讨论】:

    【解决方案2】:

    为了回答我自己的问题,这是我在客户端(Angular 端)添加的内容。 我基本上将日期时间作为查询字符串参数添加到每个发出的 AJAX 请求中。

    $httpProvider.interceptors.push(function ($q) {
        return {
          'request': function (config) {
            config.url = config.url + '?token=' + new Date().toLocaleString() ;
            return config;
          }
        }
      });
    

    【讨论】:

    • 作为替代方案:new Date().getTime() ;)
    猜你喜欢
    • 2013-09-19
    • 2017-03-27
    • 2010-12-12
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 1970-01-01
    相关资源
    最近更新 更多