Prevent multiple OPTIONS request for the same domain
Asked Answered
S

1

9

I am trying to develop a single page application (SPA) that uses as endpoint a domain that is different from the one hosted in the SPA domain (ie: site.com and site-api.com or api.site.com).

Access Control headers are already set up in the back-end, Max-Age included, however it does not seem to work.

Here's an example of what happens if I perform the same call multiple times:

google dev tools

These are the server headers:

  • Access-Control-Allow-Headers: AUTHORIZATION,CONTENT-TYPE
  • Access-Control-Allow-Methods: PATCH
  • Access-Control-Allow-Origin: http://tovertaal.test:3000
  • Access-Control-Max-Age: 600

Shouldn't Max-Age 600 prevent every other OPTIONS request within 600 seconds from the first OPTIONS request?

The server endpoint is http://tovertaal-api.test.

Siftings answered 10/7, 2018 at 15:46 Comment(0)
S
3

I have finally discovered what was the issue. It seems like Chrome DevTools, when disable cache is active, also disables CORS Origin cache, so it keeps triggering OPTIONS request for stuff that should have been cached already.

Make sure to keep caching enabled if you want to test it!

Siftings answered 17/7, 2018 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.