I've been reading a lot about this , but still there are few misunderstandings.
I read that the max-age
should be set only to static data.
I used fiddler composer to make this request
User-Agent: Fiddler
Host: www.example.com
the response is :
HTTP/1.1 200 OK
Date: Tue, 01 Jan 2013 20:37:31 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Thu, 06 Dec 2012 19:40:14 GMT <======
...
Q#1
If the server sends the last-modified
header , is it becuase that the page is a static one ? ( someone has set max-age
) at the server side ?
Q#2
After a client got this first response , the next time it will ask it is with If-Modified-Since
header and the server might return 200
or 304
(not Modified).
But why the server in his first response didn't already mention the max-age
? it could save the client from sending the second request !
Q#3
Alghough this conditional get suppose to save me from downloading the whole page , is is still discourage , so what other option do I have ? ( for static data)
Q#4
How does the iis
knows if it was modified or not ? by looking at the file date modified ? are you going to tell me that for every date check it is doing IO
access ? if not , where does it saves that info ?
Q#5
After the client got the first response it needs the page one more time. does it sending again a request with If-Modified-Since
? if no , what if the page did changed while this intreval ? and if yes - why did the server responded with max-age
header ? I have nothing to do with it.
The max-age clause of the Cache-Control header has to be enabled explicitly. The exact manner of doing so, obviously, depends on the server software.
The Last-Modified: and If-Modified-Since: interaction is independent of this, because that mechanism was invented long before max-age.
You will always get a Last-Modified: for any server side resource that the server does not know (again, by server-specific means) to be dynamically generated. Cache-Control: max-age=whatever, if also present, allows the client or cache to save on update requests (using If-Modified-Since).
But this extra header requires a server setting. It does not happen automatically for "static data". Nor does a Last-Modified: indicate "static data". (It is possible for a server side handler process to generate a Last-Modified header to be relayed to the client.)
Q1: No. The server was not configured to recognize the data as dynamic. max-age has nothing to do with it.
Q2: Because max-age was not enabled. It does not happen automatically.
Q3: No other option. If-Modified-Since was designed to save on bandwidth.
Q4: IIS, like all other servers, has to be configured to enable max-age. No guesswork involved. As for determining whether something has changed, this does involve a comparison of the date sent by the client in the If-Modified-Since header with date information stored on the server. For static data in a file this would typically involve a system call such as GetFileAttributesEx() on Windows, or fstat() on other platforms.
Q5: If a client issues an update request (with If-Modified-Since:) before a Cache-Control: max-age previously received from the server has expired, then either the client is broken, or it is executing an externally triggered "force update/refresh" option. (Note that an If-Modified-Since request pressupposes that the client still has the previous version, in some cache. If it doesn't, then it will not send this header, simply because it doesn't have the date!)