I’m using google chrome and I noticed that every time I do an XHR request I get the following headers put on the request:
Cache-Control: no-cache
Pragma: no-cache
If you read the spec at http://www.w3.org/TR/XMLHttpRequest/ it says the following
If the user agent implements a HTTP cache it should respect
Cache-Control headers in author request headers (e.g. Cache-Control:
no-cache bypasses the cache). It must not send Cache-Control or Pragma
request headers automatically unless the end user explicitly requests
such behavior (e.g. by reloading the page).
Well I’m trying the following:
$.ajax(myUrl, {
type: 'get',
dataType: 'json'
cache: true,
headers: {
'Cache-Control': 'max-age=200'
}
})
As you can see I’m explicitly setting the Cache-Control header in hopes of getting a cached copy of my resource. Well Chrome seems to ignore the Cache-Control header.
Is it possible to not send the Cache-Control: no-cache header when making an XHR request?
This was a dumb mistake. I had the Developer Tools set to “Disable Cache”. That’s why it was always adding the cache-control header. If this ever happens to you make sure you make sure that box is not checked.
Raul