Skip to main content

Conditional requests: If-Modified-Since and If-None-Match

A conditional request sends a saved date or ETag back so the server can answer 304 with no body. One page fetched twice on 2026-11-21, with status and bytes.

From our run on
  1. request 1, 2026-11-21T19:47:49+00:00, no condition
  2. last-modified:  Thu, 19 Nov 2026 22:11:52 GMT
  3. content:        577 characters, 577 bytes
  4. request 2, 2026-11-21T19:47:54+00:00, If-Modified-Since: Thu, 19 Nov 2026 22:11:52 GMT
  5. etag:           "6aff73d2-241"
  6. content:        1989 characters, 2373 bytes
How-to 11 min read

A conditional request is an ordinary GET with one extra header, If-Modified-Since or If-None-Match, that hands back the date or tag a server gave you on an earlier visit. If the server applies the condition and finds the page unchanged, it answers 304 Not Modified with no body, and you keep the copy you already have. For a tag, unchanged means the tag still matches. For a date, it means the page was last modified no later than the date you sent.

RFC 9110, the IETF standard for HTTP, defines the term more broadly: "A conditional request is an HTTP request with one or more request header fields that indicate a precondition to be tested before applying the request method to the target resource." For a client that reads pages, the precondition is the same on each visit. Send the page only if the date or tag I hold no longer matches yours.

That matters most on the second visit. A web scraping job that returns to the same addresses every day downloads mostly what it already holds, and a conditional request is how HTTP lets a server say so in a few bytes. This page covers how to send one, how to read each answer, and what came back when we tried it on a real page.

Where the validator comes from

To recheck a copy you already hold, send back a value from the response that delivered it. Servers offer two such values, and the ETag page explains both:

  • Last-Modified, the date the server believes this version of the page changed.
  • ETag, a quoted string that labels this version.

Save whichever ones arrive, next to the page, character for character. A page that sends neither gives you nothing to recheck a copy against.

That is the stored-copy workflow, and it is the one this page teaches. The RFC also allows If-Modified-Since with a date the client picks itself, from its own clock or from a Date header on an earlier response, to ask only for pages modified inside a recent window. That request is conditional too, but it tests a cutoff you chose. It does not check a copy.

This clip shows the two requests and both answers, line by line.

Ask again with the date you saved. 46 s, no sound. The words are on screen, and the captions button shows them at your own text size.
Read the transcript

Ask again with the date you saved. One page fetched twice, the second time with a condition.

The first answer carried a date and no tag. Save the date as it came. The request reads: GET /. Host: example.com. The response reads: 200 OK. Last-Modified: Thu, 19 Nov 2026 22:11:52 GMT. Last-Modified is read: date of this version. 19 Nov 2026: the date the server has for it. 577 bytes: of text came back.

Sent back, the date got a 200 and a full body, not a 304. The request reads: GET /. If-Modified-Since: Thu, 19 Nov 2026 22:11:52 GMT. The response reads: 200 OK. ETag: "6aff73d2-241". Last-Modified: Thu, 19 Nov 2026 22:10:26 GMT. If-Modified-Since is read: the date you saved. Last-Modified is read: date of this version. 200: came back, not a 304. 2373 bytes: of text came back.

A full answer may be a change, or a condition nobody applied. Reading the answer: status. 304: Keep the stored page. 200: Replace page and validators. other: Handle it as with no condition. This run: 200.

Read the full page. The page is at spider.cloud/learn/conditional-requests.

If-Modified-Since carries the date

Put the saved Last-Modified value in If-Modified-Since, unchanged:

If-Modified-Since: Thu, 19 Nov 2026 22:11:52 GMT

According to the RFC, this header makes the request depend on the page's modification date being more recent than the one you sent, and "Transfer of the selected representation's data is avoided if that data has not changed." It also names a use beyond caching that fits a crawler well: "to limit the scope of a web traversal to resources that have recently changed."

The test compares two dates and nothing else. The server does not look at the content of your copy, so a 304 here says the page's modification date is no later than the date you sent.

When you hold the server's date, send that date and leave its format alone. MDN's page on the header notes that "HTTP dates are always expressed in GMT, never in local time." A value the server cannot parse is dropped without an error, because the RFC says "A recipient MUST ignore the If-Modified-Since header field if the received field value is not a valid HTTP-date". The server then handles the request as a GET without the condition. That can end in a full page, a redirect or an error, and nothing in the answer says your header was thrown away.

If-None-Match carries the tag

Put the saved tag in If-None-Match, with its quotes and with the W/ prefix if it had one:

If-None-Match: "6aff73d2-241"

The server compares that value with the tag it holds for the page now. It compares tags, not bodies. The RFC requires the loose form of comparison here: "A recipient MUST use the weak comparison function when comparing entity tags for If-None-Match". Under that rule a tag matches whether or not either side carries the W/ prefix, so a weak tag works as well as a strong one for this header.

A match is not a promise that the bytes are the same. A server may give one weak tag to versions it considers equivalent, and MDN's example is that "two pages that differ by their creation date in the footer would still be considered identical." A 304 on a weak tag therefore says the server treats your copy as equivalent to its own. If a difference that small matters to your job, fetch the page in full and compare the content yourself.

Which one to send

Send the tag when you have it. The RFC sets the order: "A recipient MUST ignore If-Modified-Since if the request contains an If-None-Match header field". MDN's If-None-Match page says the same from the other side: "When used in combination with If-Modified-Since, If-None-Match has precedence if the server supports it."

The date is for pages that gave you no tag. In MDN's words about If-Modified-Since, "The most common use case is to update a cached entity that has no associated ETag." The first answer in the run below is that case. It carried a date and no tag, so the date is what we sent.

Reading the answer

StatusWhat it meansWhat to do
304The condition was applied and failed: the tag you sent still matched, or the page's date was no later than yours. The response has no body.Keep the stored page and note the time you checked.
200The full page came. Either the date or tag no longer matched, or the condition was not applied.Replace the stored page, and store the validators from this response.
Anything elseThe request failed or was redirected for its own reasons.Handle it as you would without the condition.

On a 304 the RFC explains why the body is missing: "there is no need for the server to transfer a representation of the target resource because the request indicates that the client, which made the request conditional, already has a valid representation". The status belongs to the 3xx group, which the status codes page walks through, but there is no Location to follow. The redirect is back to your own stored copy.

A 200 needs more care, because it has two readings. A server that applied the condition sends 200 when the page has a newer date or a different tag, and that is the correct answer. A 200 also arrives when nobody applied the condition. The status alone does not say which, so read the validators on the new response next to the ones you sent.

One page, asked for twice

The test page is https://example.com/, whose own text says it is for use in documentation examples. On 2026-11-21 we fetched it twice through the Spider API, five seconds apart. The first call carried no condition. The second carried the Last-Modified date from the first answer in If-Modified-Since.

Both bodies name the client in user_agent. return_headers adds the response headers to each page, and headers is a map of header names to values to send with the request. Put an API key in SPIDER_API_KEY to run them.

The first request, sent on 2026-11-21 at 19:47:49 UTC:

curl -s https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/", "request": "http", "return_format": "raw", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)", "return_headers": true}'

The second, sent on 2026-11-21 at 19:47:54 UTC. It is printed as we sent it, so the date in it is the one our first answer carried. When you run the pair, put the last-modified value from your own first answer in its place:

curl -s https://api.spider.cloud/scrape \
  -H "Authorization: Bearer $SPIDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/", "request": "http", "return_format": "raw", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)", "headers": {"If-Modified-Since": "Thu, 19 Nov 2026 22:11:52 GMT"}, "return_headers": true}'

Each call returned one page. The block below gives its url, status and error, the etag and last-modified values from its headers, the size of its content, and one sentence of the page's text. We measured each content string as it came back, in characters and in bytes when encoded as UTF-8. Those sizes describe the text the API returned. They are not a count of bytes on the wire.

request 1, 2026-11-21T19:47:49+00:00, no condition
url:            https://example.com/
status:         200
error:          null
etag:           null
last-modified:  Thu, 19 Nov 2026 22:11:52 GMT
content:        577 characters, 577 bytes
text in it:     This domain is for use in documentation examples without needing permission.

request 2, 2026-11-21T19:47:54+00:00, If-Modified-Since: Thu, 19 Nov 2026 22:11:52 GMT
url:            https://example.com/
status:         200
error:          null
etag:           "6aff73d2-241"
last-modified:  Thu, 19 Nov 2026 22:10:26 GMT
content:        1989 characters, 2373 bytes
text in it:     This domain is for use in documentation examples without needing permission.

What the pair shows

Both answers were 200, and both carried a body. No 304 arrived. The second body was the larger one, 2373 bytes against 577, so this pair saved nothing.

Now read the dates. We sent Thu, 19 Nov 2026 22:11:52 GMT. The second answer gives its own last modification as 22:10:26 on the same day, 86 seconds before the date we sent. The RFC's rule for that case is "If the selected representation's last modification date is earlier or equal to the date provided in the field value, the condition is false." For a false condition it says an origin server "SHOULD NOT perform the requested method if the condition evaluates to false", and should send a 304 in its place.

So this 200 does not read as a page modified after our date. The answer's own date is older than ours. The output goes no further than that. It shows the header we asked to send and the answer that came back, and it does not show whether any server evaluated the condition.

The two answers also differ from each other. The first had a date and no tag. The second had a tag and a different date. The bodies differ as well. Both hold the sentence printed above, but the first is 577 characters and the second is 1989. The second also has more bytes than characters, so part of its text lies outside ASCII, while the first is ASCII throughout.

For a client that keeps pages, two things follow. Validators belong to one response, so store the date and tag that arrived with the body you kept, and replace all of them together when a 200 brings a new body. And when a 200 follows a conditional request, compare the new validators with the stored ones, then compare the content itself if a difference would matter to you.

No 304 arrived, so this page cannot show what one looks like in these fields.

A 304 is still a request

The saving, when there is one, is in bytes. The server still accepts a connection, looks up the page and writes a reply, so a conditional request counts toward your request rate like any other. It can also be refused like any other. If a 429 or a 503 comes back, the condition changes nothing, and the Retry-After header tells you when to return.

An unchanged page does not renew your permission to fetch it either. The site's robots.txt and its terms decide that, and both can change while the page stays the same.

Do this, avoid this

Do this

  • Save the Last-Modified date and the ETag with every page you keep, exactly as they arrived.
  • Send the saved tag in If-None-Match with its quotes and any W/ prefix. If the response had no tag, send the saved date in If-Modified-Since unchanged.
  • Read the status before the body. On 304 keep your copy. On 200 replace the copy and its validators together.
  • Write down the status and the body size of both requests when you test a page, as the run above does.
  • Keep each page's validators keyed to its exact address, so the next request picks up the right pair.

Avoid this

  • Writing a date from your own clock into If-Modified-Since when you hold the server's Last-Modified value.
  • Overwriting a stored page with the empty body of a 304.
  • Sending a validator saved from one address with a request for another.
  • Deciding from the status alone that a page changed on a 200, or that every byte matches on a 304. Compare the content when the difference matters.
  • Planning a job around 304 answers before a tested pair has returned one.

Try the pair on a page of your own

Take one page you already fetch on a schedule and are allowed to read. Send the first request above with its address and look at etag and last-modified in the answer. If there is an etag, save it and send it under If-None-Match in the second request, in place of the If-Modified-Since entry. The tag's quotes are part of its value, so escape them inside the JSON body:

  -d '{"url": "https://example.com/", "request": "http", "return_format": "raw", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)", "headers": {"If-None-Match": "\"6aff73d2-241\""}, "return_headers": true}'

The server then receives If-None-Match: "6aff73d2-241", quotes included. If there is only a last-modified, as in our run, send that under If-Modified-Since. The other headers on the same response are explained on the HTTP headers page.

Then send the second request with the saved value, and write down the status and the size of content for each call, the way the block above does. A 304 means the condition was applied that time: the tag still matched, or the page's date was no later than the one you sent. It makes no promise about the next visit. If both come back 200, as ours did, the pair tells you only that this condition did not produce a 304 that day. Save the validators from the latest answer and send them next time. The incremental crawling page covers how to spot a change when the server gives you no usable signal.

Sources

  1. RFC 9110, HTTP Semantics, sections 13 and 15.4.5, IETF, June 2022 Read
  2. MDN Web Docs, If-None-Match header Read
  3. MDN Web Docs, If-Modified-Since header Read

Run this on a page you care about

The playground sends the request this page describes and shows you the response. Keyless runs work without an account and are rate limited.