Team LiB
Previous Section Next Section

Hack 54. Turn Off Absolutely All Caching

Be sure that the web page you're viewing is freshly retrieved from across the network.

You can clean up Firefox so that no old data is hanging around [Hack #8], but sometimes you might be looking for a more permanent solution. This brief hack explains how to achieve that.

5.12.1. Disable Browser Caching

To turn off the memory and disk browser caches completely, set these preferences:

browser.cache.memory.enable /* set to false, default = true */
browser.cache.disk.enable   /* set to false, default = true */

Turning these preferences off guarantees that Firefox will make an HTTP request for every URL it is asked to display.

Firefox does not use HTTP HEAD requests, at least not for the retrieval of web pages; it uses GET requests. Every URL can therefore be made to return a full copy of the resource (the web page) in question. Embedded images and other URLs are, of course, retrieved in separate GET requests. It is possible that web pages or Firefox extensions might issue their own HEAD requests, though.

GET requests never add any HTTP If-Modified-Since headers if local caching is turned off. Such headers are only sent when local caching is enabled (the default) and if a currently cached copy of the requested page was originally delivered with a Last-Modified header.

The golden rule of standard Firefox URL loading is this:

Everything is always refreshed from the Web if local caching is disabled or if the Reload (bypass cache) command is run.

Reload (bypass cache) is run with Shift-F5 (Shift and click Reload on the Macintosh). Just left-clicking the Reload button is not enough, because Reload obeys HTTP caching protocols (see the next section). Clicking Reload is enough if local caching is turned off.

Even less reliable is pressing Enter or Return in the Location bar. In that case, if local caching is still on, Firefox might not issue an HTTP request of any kind. Change this preference to 1 (one) to fix that:

browser.cache.check_doc_frequency /* 1 = everytime. default = 3 = as needed */

There is, however, an exception to the golden rule. The exception applies to uses of datasources, an advanced XUL programming topic:

The content of datasources persists until they are destroyed or until Firefox shuts down.

Datasources are an internal feature commonly exploited in XUL applications. Datasources are also used deep inside bookmarks and elsewhere.

Switching Firefox into Offline mode also affects page caching. If Firefox is in offline mode, it will attempt to use cached copies of web pages, even if the network connection is still available and it is only Firefox that is offline, not the network.

5.12.2. Disable HTTP Caching

Even when Firefox is trying to do the right thing, web pages might still be cached by HTTP caching mechanisms. In that case, web server proxies (such as squid) between Firefox and the ultimate web server can hold temporary copies of a cached file, and Firefox is denied a taste of the absolutely latest thing. For best results, make sure web pages are sent with all these HTTP headers intact:

Expires: Thu, 01 Jan 1970 00:00:00 GMT
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
Cache-Control: max-age=0, no-cache, must-revalidate

Don't set these headers in <META> tags; intervening proxies will not notice them. Instead, set them as part of the HTTP message itself.

To see the cache-related information that Firefox sends to a web server when it makes requests, just examine the HTTP headers in the browser request [Hack #51] .

If intermediate web caches and local caches are a concern, then web servers should be instructed to never return an HTTP 304 response code. The 304 code tells the browser that the server has nothing new to offer. The browser will conclude that any cached copy it has is therefore good enough.

If 304 responses can't be stopped, then ensure that no Last-Modified header line is ever sent by the server. It's that header that stimulates the browser to add If-Modified-Since headers to future requests for that page, if it's allowed to cache the page. The same argument applies to server-generated Etag headers. The existence of such headers can prompt the browser to add If-None-Match headers, which again can generate a 304 response.

5.12.3. Disable XUL Caching

By default, Firefox includes a copy of the XUL.mfl (Windows), XUL.mfasl (Unix), or XUL FastLoad File (Macintosh) file. This is the Mozilla FastLoad cache that resides in the profile area. You can set the following preference to prevent it from being used:

nglayout.debug.disable_xul_fastload /* default = false, set to true */

When FastLoad is at work, Firefox reads files directly from the chrome only if it needs to, which saves disk access time.

The general-purpose web cache is used to cache XUL files whether FastLoad is at work or not. To turn that other caching off as well, either disable caching generally as in the previous example, or else set this preference:

nglayout.debug.disable_xul_cache /* default = false, set to true */

A further hack described by some pundits is to delete the XUL.mfl file while Firefox is shut down and replace it with a directory of the same name. That makes Firefox think the FastLoad cache is corrupt or missing, and XUL files in the chrome are thus always reloaded from cache or directly. This kind of trickery is necessary only if preferences can't be set for some obscure reason.

    Team LiB
    Previous Section Next Section