What is the difference between Expires: 0
and Expires: -1
in the HTTP response header? RFC 2616 defines invalid date formats, especially including the value "0" as already expired. However, some servers (e.g. www.google.de) reply with Expires: -1
.
Is there an advantage over using -1
over 0
or is this even required for some broken HTTP clients?
The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.
When you set an expires header for a resource, such as all jpeg images, the browser will store those resources in its cache. The next time the visitor comes back to the page it will load faster, as the browser will already have those images available.
htaccess on Apache Web Server. If your web host uses the Apache web server, you can add Expires headers using the . htaccess file, which is located in the root folder of your server (the same folder that holds the wp-config.
To make it work, the expires headers need to be set by the website owner. By doing so, the browser stores the resources locally for a given period of time set through expires headers. For example, if you set expires headers on JPEG files, the browser will store all the JPEG files in its cache.
The problem is in how invalid Expires header processed by Internet Explorer (especially older versions). IE uses Trident layout engine and WinINET API to process HTTP requests. As you may know Expires could be specified in HTTP header
Expires: 0
or in meta tag
<meta http-equiv="Expires" content="0">
In second case, Expires became part of the response content (not header content), so it will be processed by Trident and then propagated to WinINET:
If WinINET downloads a response with an invalid Expires header (e.g. one that doesn’t contain a valid HTTPDATE value) and no other caching directives, it will mark the document as having expired one hour ago. Trident, however, has no such logic. If you specify an invalid time, Trident grabs the current timestamp and uses that as the expiration. Trident will also use the current timestamp if it encounters the Pragma: no-cache directive. If the user tries to re-navigate to the current document during same exact second that the HTTP/404 was processed, the incorrectly-updated expiration of the existing cache entry will result in it being treated as fresh for that request. If the user hit the Refresh button or F5, the cache would be bypassed and the 404 page would be shown.
In other words Expires: 0
not always leads to immediate resource expiration, therefore should be avoided and Expires: [some valid date in the past]
should be used instead.
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