Max Koretskyi
Max Koretskyi

Reputation: 105497

image request - response status 200 or 304

I request an image from server. Sometimes it returns the image with the statuscode 304, and sometimes with the statuscode 200. How does server decide which statuscode to return? The manual states the 304 is returned if the file hasn't been modified - but I don't understand it: modified compared to what version, compared to which request, etc? Please elaborate.

Upvotes: 0

Views: 3194

Answers (2)

Anil Shanbhag
Anil Shanbhag

Reputation: 968

Let me illustrate with an example. Below are request and response headers for your image thumbnail.

Request URL:https://www.gravatar.com/avatar/37c44d25d19d63d3107a8c7154568060?s=32&d=identicon&r=PG
Request Method:GET
Status Code:304 Not Modified

Request Headers

Accept:image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:__qca=P0-584450804-1358798303046
Host:www.gravatar.com
If-Modified-Since:Wed, 11 Jan 1984 08:00:00 GMT
Referer:http://stackoverflow.com/questions
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

Response Headers

Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Cache-Control:max-age=300
Date:Wed, 08 Jan 2014 20:27:08 GMT
Expires:Wed, 08 Jan 2014 20:32:08 GMT
Last-Modified:Wed, 11 Jan 1984 08:00:00 GMT
Server:ECS (sea/1C32)
Via:1.1 varnish
X-Cache:HIT
X-Varnish:1925324757 1925322482

As you can see, the If-Modified-Since field in the request header is used by the server to decide whether to simply return 304 or if the file was modified after this date return the new contents along with 200.

Upvotes: 1

Daniel C
Daniel C

Reputation: 1362

References:

RFC

Real world explanation

Effectively you should only get a 304 if you sent a If_Modified_Since header.

Upvotes: 0

Related Questions