Introduction
The HEAD method is a lightweight HTTP request method used to retrieve the headers of a resource without downloading the body. It behaves exactly like a GET request but does not return the response content.
HEAD is extremely useful for checking resource availability, file size, caching rules, content type, and server metadata—without consuming unnecessary bandwidth.
This method powers many behind-the-scenes optimizations in browsers, CDNs, SEO crawlers, and download managers.
What Is a HEAD Request?
A HEAD request asks the server to send only the headers of a resource, not the body.
Key Characteristics
- Same response headers as GET
- No response body
- Faster and bandwidth-efficient
- Safe and idempotent
- Commonly used to check if a resource exists
Why HEAD Is Important
HEAD is essential for tasks like:
- Checking if a webpage exists before making a full GET
- Validating download size before downloading
- Verifying last modification date
- Checking content type (HTML, JSON, PDF, image, etc.)
- SEO bots verifying link validity
- Caching systems confirming freshness
- Monitoring server uptime
When Should You Use HEAD?
Use HEAD when you need information about a resource without needing the resource itself.
Examples:
- Checking if an image URL is valid before rendering
- Checking if an API endpoint is reachable
- Determining file size before downloading
- Testing if a link is broken
- Verifying server metadata without heavy GET operations
How HEAD Works Internally
- Client sends HTTP HEAD request to a resource URL
- Server processes it like a GET request
- Server returns only headers
- No body content is included
- Client uses headers for decision-making
Example 1: JavaScript Fetch API (HEAD Request)
fetch("https://example.com/image.jpg", { method: "HEAD" })
.then(res => {
console.log("Status:", res.status);
console.log("Content-Length:", res.headers.get("Content-Length"));
console.log("Content-Type:", res.headers.get("Content-Type"));
})
.catch(err => console.error(err));
Explanation
- Content-Length tells file size
- Content-Type tells what kind of resource it is
- Status tells whether the resource exists (200, 404, etc.)
Example 2: HEAD with cURL
curl -I https://example.com
Common Output
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 24890
Last-Modified: Wed, 20 Nov 2025 10:00:00 GMT
curl -I stands for “show headers only.”
Example 3: HEAD Endpoint in Express.js (Node.js)
app.head("/api/check", (req, res) => {
res.set({
"X-Server-Status": "Running",
"X-Version": "1.0.2"
});
res.status(200).end();
});
Explanation
- Sets custom headers
- No body is returned
HEAD vs GET
| Feature | HEAD | GET |
|---|---|---|
| Body Returned | ❌ No | ✔ Yes |
| Resource Loading | Fast | Complete |
| Primary Use | Metadata check | Full resource access |
| Network Cost | Very low | High |
| Idempotent | Yes | Yes |
HEAD is perfect when you want to check something without downloading it.
Common Response Codes for HEAD
| Code | Meaning |
|---|---|
| 200 OK | Resource exists |
| 301/302 Redirect | Resource moved |
| 404 Not Found | Resource missing |
| 500 Server Error | Server failed to process |
HEAD typically mirrors statuses of GET.
Advantages of HEAD
- Saves bandwidth
- Faster response
- Perfect for link checking
- Useful for caching
- Good for SEO and monitoring
Disadvantages of HEAD
- Limited functionality
- Not all servers handle HEAD correctly
- Some APIs do not implement HEAD explicitly
Real-World Use Cases
1. Checking if a file exists before downloading
A download manager uses HEAD to show file size.
2. SEO link validators
Google-like bots verify pages exist without loading the content.
3. CDN cache checks
Cloudflare, Akamai, etc., rely on HEAD to determine resource freshness.
4. Website uptime checks
Monitoring tools perform HEAD ping checks.
