admin管理员组

文章数量:1326277

We have a REST api which works in Chrome but we found that cached results are used in IE.

In order to fix customers have to go to internet options and change the setting 'Check for the newer version of stored pages" to 'Every time I visit the web page'.

I have seen that I could put at datetime at the end of each of my requests using javascript like so

 /v1/getInfo?Date = (new Date()) 

However this means I have to tell all the customers to do this.

Is there a better way of doing this so that my requests look like

 /v1/getInfo 

without changing the URL?

We have a REST api which works in Chrome but we found that cached results are used in IE.

In order to fix customers have to go to internet options and change the setting 'Check for the newer version of stored pages" to 'Every time I visit the web page'.

I have seen that I could put at datetime at the end of each of my requests using javascript like so

 /v1/getInfo?Date = (new Date()) 

However this means I have to tell all the customers to do this.

Is there a better way of doing this so that my requests look like

 /v1/getInfo 

without changing the URL?

Share Improve this question asked Jul 8, 2015 at 15:13 JD.JD. 15.6k22 gold badges92 silver badges165 bronze badges 1
  • You can add HTTP headers to instruct the browser not to cache. – Lloyd Commented Jul 8, 2015 at 15:15
Add a ment  | 

2 Answers 2

Reset to default 4

For this task, you should set up the correct HTTP Headers in your application. The caching is controlled by the Cache-Control header:

Cache-Control: no-cache

Though in itself, this is not bulletproof, so you may need to set up other headers too. This guide seems like a nice writeup.

Check what headers your API is returning. In particular check the configuration of Expires and Cache-Control headers. Those are what inform browsers/clients to store a local copy of the message body and to use that next time they request the same resource.

本文标签: javascriptHow to avoid caching in IE with REST ApiStack Overflow