Cache web page
When your site visitors visit your site, their browser may cache many of the page objects, so that subsequent requests for the same objects will be instant. To cache web page, you need to add expires headers.
Speeding Up Your Website
To have a caching website, first you need to know what objects are on your page and then you can tell your web server to add expires headers. Read on to see how easy speeding up your website can be.
If you go to http://www.webpagetest.org/ and open the Advanced Options, you’ll notice a default option of “First View and Repeat View”. Repeat view is what visitors will experience on subsequent visits to your site.
One thing to note, however, is the repeat page may be deceiving. Browsers will often cache static objects in the current session, even in the absence of expires headers. This is good for subsequent page views in the same browser session, but won’t persist a browser close/open. Look for the “Cache Static Content” button at the top right to see what grade your site received and click it.
You’ll see a listing of objects missing expires headers, or with short lived expires headers, like this:
How to edit .htaccess to add expires headers
In the example above, there are a number of font files that end in “woff” missing expires headers. To add expires headers to this type of file, you need to know the content type of woff files. To determine this, go to the webpagetest Details page to see the Waterfall View. Click on [one of] the file[s] to bring up the request/response details. Click on the Response link. Take note of the Content-Type.
Now, edit your .htaccess file and add the following. Notice the “application/x-font-woff”, relevant to this example. The other content types are just a good idea.
Rerun webpagetest. Did your “cache static content” grade improve?
In this example, I eliminated the FAILED and WARNING on the woff, css and js files. The remaining tracking pixels I’ll ignore, because they are served outside of my control and need not be cached; a trade off for tracking information.
Lastly, a warning about adding expires headers to your static content. If you change a file, your repeat site visitors won’t get the new file. Combat this problem by not changing files. If you need to update an image, for example, upload a new image with a new filename. Then change your HTML source to use the new filename. This point is hard for people to understand and why most hosting providers don’t enable mod_expires by default. If you can handle this caveat, you’ll enjoy a major performance enhancement on your site.