How to add Expires or Cache-Control Header

This standard has two simple goals for adding Expires or Cache-Control Header

For static files: implement "Never expire" as Expires Header for the next visits.

For dynamic files: use the most appropriate "Cache-Control Header" to assist the browser in HTTP calls.

Web page layouts get richer and richer, rendering more Flash scripts, style sheets, images, and animations in the content. A first time visit to the page can contain many HTTP calls, but using a Header Expires will allow those components to be cached. This avoids unnecessary HTTP calls on subsequent visits. Expires Headers are used very often with images, but should be used with all components including scripts, style sheets, and Flash animations.

Browsers (and proxies) use the cache to reduce the number and size of HTTP requests, allowing the web page to load faster. A web server uses Expires Headers in HTTP responses to tell the client how long a component can be in the cache. This is a very long Expires Header, telling the browser that this response will not expire until April 15, 2010.

Expires: Thu, 15 Apr 2010 20:00:00 GMT

If your server is Apache, use the ExpiresDefault directive to determine an expiration date relative to the current date. This example of the ExpiresDefault directive sets the expiration date to 10 years from the time of the request.

ExpiresDefault "access plus 10 years"

Remember, if you use a very long Expires header, you must rename the component file every time you modify it.

Using a long-term Expires header, it only affects the pages viewed after a user has visited your site. It has no effect on the number of HTTP requests when a user visits your site for the first time and the browser cache is empty. Therefore, the performance improvement depends on how often your users visit your pages with a primed cache. (A primed cache already contains all the components on the page.) Using a long-term Expires header will increase the number of components that are cacheable by the browser and reuse them on subsequent visits to the page, without the need. to send a single byte to the client.

Date update on 2020-11-13. Date published on 2020-11-13. Category: Computer class Author: Oscar olg Fuente: tecnologia