In Apache's mod_expires module, there's the Expires directive with two base cycles, access, and modification.

ExpiresByType text/html "access plus 30 days"

naturally implies that the cache will request fresh content after thirty days.

However,

ExpiresByType text/html "modification plus 2 hours"

does not make intuitive sense.

So how exactly does the browser cache realize that the file continues to be modified unless of course it can make a request towards the server? And when it's creating a call towards the server, what's the utilization of caching this directive? It appears in my experience that i'm lacking the knowledge of some crucial a part of caching. Please enlighten me.

An Expires* directive with "modification" since it's base refers back to the modification duration of the file around the server. If you set, say, "modification plus 2 hrs", any browser that demands content within 2 hrs following the file is modified (around the server) will cache that content until 2 hrs following the file's modification time. And also the browser knows when that point happens because the server transmits an Expires header using the proper expiration time.

Allow me to explain by having an example: say your Apache configuration includes the road

ExpiresDefault modification plus 2 hours

and you've got personal files index.html, that the ExpiresDefault directive is applicable to, around the server. Suppose you upload a version of index.html at 9:53 GMT, overwriting the prior existing index.html (if there is one). Now the alteration duration of index.html is 9:53 GMT. Should you be running ls -l around the server (or dir on Home windows), you'd view it within the listing:

-rw-r--r--  1 apache apache    4096  Feb 18 09:53 index.html

Now, with every request, Apache transmits the Last-Modified header using the last modification duration of the file. Because you obtain that ExpiresDefault directive, it will likewise send the Expires header having a time comparable to the alteration duration of the file (9:53) plus two hrs. Here is a component of the items the browser sees:

Last-Modified: Wed, 18 Feb 2009 09:53:00 GMT
Expires: Wed, 18 Feb 2009 11:53:00 GMT

When the time where the browser makes this request is before 11:53 GMT, the browser will cache the page, since it has not expired. Therefore if the consumer first visits the page at 11:00 GMT, after which would go to exactly the same page again at 11:30 GMT, the browser notice its cached version continues to be valid and won't (in other words, is permitted to not) create a new HTTP request. When the user would go to the page another time at 12:00 GMT, the browser understands that its cached version has expired (it's after 11:53) therefore it discards the cache and demands a brand new version from the page. Obviously, should you haven't transformed the file meanwhile, Apache will be sending back exactly the same page, with similar values for that Last-Modified and Expires headers - the alteration duration of the file has not transformed. This time around, though, the browser understands that the need for the Expires header is prior to the current time (11:53 < 12:00) therefore it does not cache the page whatsoever.

Now, let us pretend rather that you simply submitted a brand new version from the page at 11:57. Within this situation, the final modification duration of the file becomes 11:57, and Apache computes the expiration time as 11:57 + 2:00 = 13:57 GMT. Now, once the browser demands a brand new version from the page at 12:00, it will get both of these headers rather than the 2 in the above list:

Last-Modified: Wed, 18 Feb 2009 11:57:00 GMT
Expires: Wed, 18 Feb 2009 13:57:00 GMT

And today it understands that the expiration time is more than the present time (13:57 > 12:00) therefore it caches the page, and also the cycle repeats...

(Note obviously that lots of other activities are sent together with the 2 headers I in the above list, I simply trimmed out all of the relaxation for simplicity)

My understanding is the fact that modification asks the browser to base the cache time in line with the Last-Modificatied HTTP header's value. So, modification plus 2 hrs will be the Last-Modificatied time + 2 hrs.