Course contentsShow
← Web Development
Lesson 835 of 2,98215. Browser NetworkingFree lesson

Request Modes: cors, no-cors, same-origin, navigate

Understand request mode options and their implications for CORS, security, and response access.

Request Modes: cors, no-cors, same-origin, navigate

You'll learn: How the mode option in fetch() controls cross-origin behavior, security enforcement, and what response data you can access.

What Is Request Mode?

When you make a fetch() request, the mode option tells the browser how strictly to enforce same-origin security policies and what kind of response access you'll get. Think of it like choosing security levels at an airport checkpoint—each mode has different rules about what crosses the border.

The Four Request Modes

cors (Default)

Allows cross-origin requests that follow CORS rules. The server must send appropriate CORS headers (Access-Control-Allow-Origin), or the request fails. You get full access to the response if allowed.

fetch('https://api.example.com/data', {
  mode: 'cors' // default, follows CORS protocol
});

no-cors

Makes cross-origin requests but severely limits response access—you can't read status, headers, or body. Used mainly to cache resources or trigger server-side effects when you don't need the response.

fetch('https://other-site.com/log', {
  mode: 'no-cors' // opaque response, can't read it
});

same-origin

Rejects any cross-origin request outright. Ensures you only communicate with your own origin. Useful for extra security when you know requests should never leave your domain.

fetch('/api/user', {
  mode: 'same-origin' // fails if URL is different origin
});

navigate

Reserved for browser navigation requests (like page loads). Rarely used directly in fetch().

Why This Matters

The mode directly impacts security and what data you can access. cors provides transparency but requires server cooperation. no-cors bypasses CORS errors but leaves you blind to the response—a trade-off between making the request and reading the result.

Key Takeaway: Request modes control cross-origin enforcement and response accessibility—cors for transparent API calls, same-origin for strict security, and no-cors when you need to send but can't read responses.