Caching information can help to reduce the number of resources downloaded by a device. This test determines if cache information has been included with your page.
Caching
If the browser determines that a requested file is already in its local cache, then it will use the local copy instead re-fetching the network copy if it has not expired. The browser uses cache information to determine if its local copy has expired. By providing cache information, you help the browser optimise its network usage.
What value?
Ready.mobi checks that a Cache-Control header has been sent with your page. The value of the cache-control header does not affect the overall ready.mobi score. However, if you set your cache-control to no-cache, or max-age=0, then the result of this test will be a WARN.
You should set expiry times appropriate to your application. For instance, for some applications where the data is constantly chaning .g. financial data, you might wish to prevent caching altogether, whereas applications with relatively static data should set a high expiry time.
Setting the Cache-Control header
Meta http-equiv tags
The meta http-equiv tag enables you to inform the HTTP server about the kinds of headers it may provide. If you do not have access to the server directly, but if you are able to modify your html pages then you can use a http-equiv meta tag directly in your content. Include the following line at the top of your page:
<meta http-equiv="Cache-Control" content="max-age=200" />
This will set the cache to expire after 200 seconds. Note that setting the cache control to max-age=0 has the same effect as no-cache
There are many other possible values for the Cache-Control header. To find out more please see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
Using server side code
If you are using server side code to genereate your content then there is usually a method to set the server headers directly from within your server source code. Some examples are included below. Just change the value max-age=200 to whatever is appropriate for your application.
- Java Servlets: Use the setHeader method:
- JSP: Use the Java servlet method as above, but wrapped in scriptlet tags (i.e. <%….%>) , and before any other output
- PHP: include the line
- ASP: include the line
response.Expires = -1
before any content is sent
- Perl: include the line
print "Cache-Control: max-age=200 ";
before any output is sent to the client.
- Python: As for Perl, but no semicolon required at the end
- Coldfusion: <CFHEADER NAME="Cache-Control" VALUE="max-age=200">
response.setHeader("Cache-Control", "max-age=200");
before any content is sent
header ("Cache-Control: max-age=200 ");
before any other output line
Reference
This test is based on a W3C mobileOK best practice test. See http://www.w3.org/TR/mobile-bp/#CACHING for more details