Is it possible to cache HTTP OPTIONS response?
Asked Answered
T

2

10

I am making CORS calls. Now, every api call has a OPTIONS preflight call. Is it possible to cache the OPTIONS preflight call?

I see that Cache-Control header can be used to cache actual GET response. https://www.fastly.com/blog/caching-cors

But how do I cache the response of the OPTIONS call?

Tempt answered 22/1, 2019 at 3:51 Comment(2)
You can’t control client-side browser caching related to the CORS preflight OPTIONS request. The browser controls caching for that on its own. The only means you have for affecting caching of that is to use the Access-Control-Max-Age response header fetch.spec.whatwg.org/#http-access-control-max-age developer.mozilla.org/en-US/docs/Web/HTTP/Headers/…. Note that Chrome will only cache preflight OPTIONS responses for a maximum of 600 seconds (10 minutes) no matter how high you set the value of that header.Ethics
Well, you can cache it with AWS Cloudfront, the AWS cloud platform's CDN. So the CDN communicates with a backing server and can then cache the OPTIONS response. Not sure if it should be done though..Pastore
S
0

Caching HTTP OPTIONS for CORS preflight requests is a sensible thing.

If the response body is exactly the same for all the CORS preflight requests for any browser version, origin or client, then you may activate HTTP OPTIONS caching.

If unsure, leave the HTTP OPTIONS without caching to prevent breaking HTTP CORS based requests ... after all the HTTP OPTION requests are very light and quick compared with the actual HTTP flight request (and on top of that, the browsers made already a client side cache for the HTTP OPTIONS preflight requests for CORS).

Slide answered 19/12, 2022 at 14:56 Comment(1)
"then you may activate HTTP OPTIONS caching" - how do I do that?Sheepshead
R
0

According to this:

Responses to this method are not cacheable.

Returnable answered 25/3, 2023 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.