Rule 3--Add Expires header
When designing a Web page, the response time of the first visit is not the only thing to consider. If that's the case, we can use rule 1 to the extreme and no longer place any pictures, scripts, and stylesheets on the page. However, we all know that images, scripts, and stylesheets can enhance the user experience, although this means that the page takes longer to load. Rule 3, described in this chapter, shows how to configure components to maximize the browser's caching capabilities to improve page performance.
Today's Web pages contain a number of components and are growing in number. The initial visitors to the page make a lot of HTTP requests, but by using a long expires header, these components can be cached. This avoids unnecessary HTTP requests in subsequent page views. Long expires heads are most commonly used in images, but should be used on all components, including scripts, stylesheets, and Flash. Many top-level websites have not yet done so.
Expires Head
browsers (and proxies) use caching to reduce the number of HTTP requests and to reduce the size of HTTP responses, making Web pages load faster. The Web server uses the expires header to tell the Web client that it can use the current copy of a component until the specified time. The HTTP specification briefly says the header is "after this date/time, the response will be considered invalid."
Max-age and Mod_expires
Before explaining how the cache can improve transport performance well, it is important to mention a different option than the expires header. HTTP1.1 introduced the Cache-control head to overcome the expires head limit. Because the expires header uses a specific time, it requires a clock-like synchronization between the server and the client. In addition, the expiration date needs to be checked for postpartum, and once the coming day arrives, a new date will need to be provided in the server configuration.
In another way, Cache-control uses the max-age directive to specify how long the component is cached. It defines an update window in seconds. If the number of seconds since the component was requested has been less than Max-age, the browser uses the cached version, which avoids additional HTTP requests.
Using Cache-control with Max-age can eliminate expires limitations, but for browsers that do not support HTTP1.1 (although this accounts for only 1% of your traffic), you may still want to provide a expires header, and you can specify both response headers-- Expires and Cache-control Max-age. If you do your duty, you still need to worry about the clock synchronization and configuration maintenance issues that expires brings.
14 Rules for performance Improvement (III)