Simple vs Preflight Requests
You'll learn which cross-origin requests are "simple" and sail through immediately versus which require a preflight security check first.
When a browser makes a cross-origin fetch request, CORS determines whether the server will allow it. Not all requests are treated equally—some are considered simple requests and go straight through, while others trigger a preflight request: an extra OPTIONS request sent before your actual request to ask the server's permission.
What Makes a Request "Simple"?
A request is simple if it meets all these criteria:
- Method must be
GET,POST, orHEAD - Headers must only include "safe" ones like
Accept,Content-Language, orContent-Type - Content-Type (if used) must be
application/x-www-form-urlencoded,multipart/form-data, ortext/plain
Think of simple requests like walking into a shop that's already open—you just walk in. No special permission needed because you're doing something routine.
What Triggers a Preflight?
If your request uses:
- Methods like
PUT,PATCH, orDELETE - Custom headers (e.g.,
Authorization,X-Custom-Header) Content-Type: application/json
...the browser sends an OPTIONS request first, asking "May I send this type of request?" The server must respond with proper CORS headers (Access-Control-Allow-Methods, Access-Control-Allow-Headers) before your real request proceeds.
Preflights are like calling ahead to ask if you can bring something unusual into the shop—you need explicit permission first.
Why This Matters
Simple requests are faster (one round-trip). Preflight requests add latency (two round-trips). Understanding which is which helps you optimize performance and debug CORS issues.
Key Takeaway: Simple requests (GET/POST with standard headers) skip preflight checks; complex requests (custom methods/headers, JSON payloads) require preflight OPTIONS requests for security.