I have a webpage that I am caching for 12 hours. These are two screenshots of the response headers.
and
As you can see both the 'Date' and 'Expires' header have changed in values. My understanding is that 'Date' is the time when file is requested by us and 'Expires' is the time when the browser is supposed to check for a newer version. After an interval of four minutes both the values have updated. So, how does browser decide when it is time to request newer version of file? Will it not cause the file to be cached indefinitely?
I understand that the 'Expires' value is just a suggestion for the browser. But how does browser know the time when the file was requested for first time because 'Date' header also gets updated each time.
I have one more question. My webpages have .php
extension. However, my header shows:
Content Type : "text/html"
Why is this happening? Content Type : "text/html"
causes my webpages to be cached. Caching does not happen on pages that have session_start()
? Is it because of the session_start()
or is it just a coincidence?
HTTP 'Date' header is just the current date and time on the server. See the RFC for more details. It has no relation whatsoever to the resource (file/page) being served
HTTP 'Expires' header is an advice for browser, usually it's set in your web server config or directly in the application code. In most cases it's current time + some extra hours/days as seen reasonable by webmaster. So if expiration is set to, let's say, 3 days – 'Expires' will always show current time in 'Date' field and current time + 3 days in 'Expires' field. Doesn't really matter when the file was updated, it has no effect.
If your browser has this file in cache and the original 'Expires' moment hasn't arrived yet – browser will use the cached version. There are some ways to force update though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With