简体   繁体   English

MEAN堆栈-Express-在IE 11中缓存页面-304状态码

[英]MEAN stack - Express - Page getting cached in IE 11 - 304 status code

I am using MEAN stack to develop my application. 我正在使用MEAN堆栈来开发我的应用程序。 The application is working fine in chrome but when the page is opened in IE, and when user request for a page, I get 304 status from the server. 该应用程序在chrome中运行正常,但是在IE中打开该页面时,以及当用户请求页面时,我从服务器获取304状态。 Because of this cached page is served back to the user. 由于此缓存的页面被送回给用户。

Interesting part is, if I open IE developer tool bar & then select network tab and record various request, the app starts to work fine. 有趣的是,如果我打开IE开发人员工具栏,然后选择“网络”标签并记录各种请求,则该应用程序将开始正常运行。 I start to get 200 response from server. 我开始从服务器收到200响应。

So far I have tried this: app.disable('etag'); 到目前为止,我已经尝试过: app.disable('etag');

and this : 和这个 :

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

But both the options did not work for me. 但是,这两种选择都不适合我。

Have you tried setting the cache headers described here: https://stackoverflow.com/a/9886945/442472 . 您是否尝试过设置此处描述的缓存头: 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

I think that etag on its own doesn't allow browsers to understand what the server side desired caching strategy should be. 我认为etag本身不能使浏览器了解服务器端所需的缓存策略应该是什么。 etags are really just a way to identify a server side resource via a checksum. etags实际上只是一种通过校验和识别服务器端资源的方法。

To answer my own question, this is what i added on the client side (Angular Side). 为了回答我自己的问题,这就是我在客户端(角度侧)添加的内容。 I am basically adding date time as a query string paramter to every out going AJAX request. 我基本上是将日期时间作为查询字符串参数添加到每个发出的AJAX请求中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM