Dung (Donny) Nguyen

Senior Software Engineer

HTTP HEAD Method

The HTTP HEAD method is a request method used to retrieve metadata about a resource without actually downloading its content. This is useful for checking the availability, size, and last modification date of a resource before deciding whether to download it.

How it works:

  1. Request:
    • The client sends an HTTP HEAD request to the server, specifying the URL of the resource.
  2. Response:
    • The server responds with an HTTP status code (e.g., 200 OK, 404 Not Found) and a set of headers.
    • The headers typically include information like:
      • Content-Length: The size of the resource in bytes.
      • Last-Modified: The last time the resource was modified.
      • Content-Type: The MIME type of the resource.

Key advantages of using the HEAD method:

Common use cases:

Example:

If we want to check the size of a large image file before downloading it, we can send a HEAD request to the image URL. The server will respond with the Content-Length header, indicating the file size. We can then decide whether to proceed with the download based on the file size.

By understanding and using the HTTP HEAD method, we can optimize our web applications and improve their performance.