Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Expires header values "0" and "-1"

Tags:

http

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?

like image 615
scai Avatar asked Jul 06 '12 07:07

scai


People also ask

What is expired HTTP header?

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.

What will happen if you set an Expires header to a later date say 1 day )?

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.

How do you add expired headers in HTML?

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.

How do you fix add expires headers?

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.


1 Answers

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.

like image 79
Pavel Podlipensky Avatar answered Sep 30 '22 11:09

Pavel Podlipensky