Chrome does not cache preflight

I am implementing a REST API that should support cross-domain requests. Using CORS, I want to achieve this. Almost all of my requests are "not simple", which means for all requests other than GET, a pre-check request must be sent by the browser.

To limit the number of preflight / OPTIONS requests, I am trying to allow the browser to cache OPTIONS requests. This seems to work in Firefox and Safari, but not in Chrome. I know that Chrome will only cache pre-sales requests in just 10 minutes, but in my case, it doesn't seem to be caching at all.

These are the HTTP requests and responses sent / received by Chrome:

Request:

OPTIONS /api/v1/sessions HTTP/1.1 Host: xxxxxxx Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Access-Control-Request-Method: POST Origin: http://localhost:8000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36 Access-Control-Request-Headers: content-type Accept: */* Referer: http://localhost:8000/ Accept-Encoding: gzip, deflate, sdch Accept-Language: nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4 

Answer:

 HTTP/1.1 200 OK Date: Sun, 26 Jul 2015 09:33:27 GMT Server: Apache/2.4.7 (Ubuntu) X-Powered-By: PHP/5.5.9-1ubuntu4.9 Cache-Control: private, max-age=1440, pre-check=1440 Access-Control-Allow-Origin: http://localhost:8000 Access-Control-Allow-Methods: GET,POST,PATCH,DELETE Access-Control-Max-Age: 86400 Access-Control-Allow-Headers: content-type Content-Length: 0 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=utf-8 
+7
google-chrome caching cors preflight
source share
1 answer

You have Pragma: no-cache & Cache-Control: no-cache headers Cache-Control: no-cache set in the request.
Try to remove them.

By default, API requests do not set these headers, and I doubt Chrome either.
You should check your code and find out where they are installed.

Now, given that it works fine in other browsers, you should also check if you have set the no-cache option in the developer tools.

+10
source share

All Articles