Access-Control-Max-Age: How long the browser may cache the preflight response. Avoids OPTIONS round trips. Access-Control-Max-Age tells the browser how long it may remember a preflight response, in seconds. During that time, repeated cross-origin requests skip the extra OPTIONS round trip. Without it, a browser may send a preflight before every single API call that needs one. On a busy single-page application, that can double the number of requests and add noticeable delay, especially on slow mobile connections.
Frequently asked questions about Access-Control-Max-Age
What should you keep in mind with Access-Control-Max-Age?
A value of 600, ten minutes, is a reasonable default. Browsers cap it anyway; Chrome allows at most two hours. Set it once your CORS configuration is stable. While you are still changing allowed headers or methods, a long cache can make it look as if your changes had no effect, because the browser keeps using its remembered answer.
What does an example of Access-Control-Max-Age look like?
Use when reviewing or setting HTTP response headers for a web app or API - security headers (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy), CORS headers, caching headers (Cache-Control, ETag, Last-Modified, Vary) and cookies (Set-Cookie flags). Also use when a security scan reports missing headers.
Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.
'Expert-level browser automation, debugging, and performance analysis using Chrome DevTools MCP. Use for interacting with web pages, capturing screenshots, analyzing network traffic, and profiling performance.'