Knowledge base glossary

What is a Preflight Request - A short definition

1 minute reading time

A preflight request is a type of HTTP request sent by a web browser to a server before making a main request. It’s used to determine if the server will accept the main request, and to gather information about the server’s capabilities and requirements.

Here’s a breakdown of how preflight requests work:

  1. Browser Determines Need for Preflight: The browser checks the main request’s HTTP method (e.g., PUT, DELETE, PATCH), headers, and other factors to determine if a preflight request is necessary.
  2. Browser Sends OPTIONS Request: If a preflight is needed, the browser sends an OPTIONS request to the server. This request includes the HTTP method, headers, and URL of the main request.
  3. Server Responds with Allowable Methods and Headers: The server responds to the OPTIONS request with a 200 OK status code and a list of HTTP methods and headers that it allows for the main request.
  4. Browser Makes Main Request: If the server’s response indicates that the main request is allowed, the browser sends it.
Preflight requests are essential for ensuring cross-origin resource sharing (CORS) compatibility. CORS is a mechanism that allows web pages to make requests to servers on different domains. Preflight requests help to verify that the server supports the necessary CORS settings for the main request to be successful.

Here are some common scenarios where preflight requests are used:

  • Cross-origin AJAX requests: When a web page makes an AJAX request to a server on a different domain, a preflight request is often sent to check if the server allows cross-origin requests.
  • WebSockets: WebSockets are used for full-duplex communication between a web browser and a server. A preflight request is typically sent before establishing a WebSocket connection to ensure compatibility.
  • Fetch API: The Fetch API is a modern API for making network requests in JavaScript. Preflight requests are automatically handled by the Fetch API.

In summary, preflight requests are a crucial part of the HTTP protocol, ensuring that web applications can communicate effectively across different domains and platforms.

Profielfoto Freek Kampen

By Freek Kampen

Data & Analytics specialist and co-owner of New North Digital. With a background in online advertising, I solve tracking and data issues for entrepreneurs and agencies. Feel free to get in touch!

Looking for more answers?

Check out our knowledge base for more terms like Preflight requests. Level up your knowledge with our articles on core concepts in web analytics.

Continue learning
Compare list
Close
Get help

Send us a message