Using cache effectively

Mobile browsing cache considerations

Latency and data transfer speeds are more significant considerations when browsing on a mobile device than when browsing on a desktop computer. Connecting via WLAN improves performance but this is up to the mobile device user so cannot be relied upon.

The S60 Browser's data cache stores recently received content. One way to enhance the browser experience is to use device cache in a efficient manner. Doing so can help performance by speeding up the page-rendering process and keeping latency and the need to transfer data between the network and the client device to a minimum.

Follow the guidelines in this section to use cache effectively in the S60 Browser.

Use Expires in place of Cache-control

Use an expiration header rather than cache-control for content that is not time-critical. Cache-control validation mechanisms such as ETag and Last-Modified cause calls to the network server for content updates, which negatively impact performance. The simpler expiration header does not result in this constant communication between the browser and the server.

For example, the following expiration header sets a date far in the future, essentially making the content static.

Expires: Fri, 1 Jan 2011 20:00:00 GMT

The following cache-control header causes updates every 5 minutes (300 seconds):

Cache-Control: max-age=300, must-revalidate

For more information about HTTP caching, see the Paul James article HTTTP Caching.

Reuse CSS and script files

You should define styles and JavaScript that are used throughout the website in external files that can be downloaded and cached. This provides a way for multiple Web pages in your site to reuse styles and script. To cache the files, link to them in the <head> section of the document.

<head>
<link rel="stylesheet" href="styles/main.css" type="text/css">
<script type="text/javascript" src="scripts/common.js></script>
</head>

Note that caching CSS and JavaScript is not recommended for styles or script that are applied to one Web page only. In this case, it is more efficient to define the script or styles inline rather than downloading multiple files. If you have a large website you may want to use a combination of caching and inline mechanisms to achieve the best performance. For more information see, Inline styles vs. external style sheets

Remember device cache limitations

You should be careful when caching files on a mobile device. Cache size is limited and the amount of cache available is device-dependent. You should expect it to be smaller than what is available on a desktop PC. For example, you cannot rely on certain files, such as large images, remaining in the device cache for the entire duration of the browsing session. The browser may have to reload them after they expire from the cache.