Skip to navigation

malevolent design weblog

This blog is now defunct, but you can find more stuff over at my personal site

Preventing Prefetching

Software such as Fasterfox and Google Web Accelerator loads content in advance by following links behind the scenes, the idea being that when you then click on something it’ll appear quickly. I’ve got little sympathy for developers’ gripes about screwed-up web applications, but prefetching does distort activity stats and puts an extra burden on hosting.

To use a tenuous analogy: it’s like going into an all-you-can-eat restaurant and lining up 10 overflowing plates of different foods just in case you fancy a nibble from one of them later. It’s a bit selfish, goes against the way the web’s supposed to work, and doesn’t actually make an awful lot of difference on a fast connection, so please steer clear of these packages.

If you’re a site owner and want to minimise prefetching, firstly put this in your robots.txt file:

User-agent: Fasterfox
Disallow: /

That’ll tell newer versions of Fasterfox to not prefetch. Next, if your hosting permits it, you can put this into .htaccess:

RewriteEngine On
RewriteCond %{HTTP:x-moz} ^prefetch$ [NC]
RewriteRule ^.* - [F,L]

The web server should then reject prefetching requests from GWA, as those include an x-moz: prefetch header.

Alternatively, you could put this at the start of PHP pages:

if ((isset($_SERVER['HTTP_X_MOZ'])) && ($_SERVER['HTTP_X_MOZ'] == 'prefetch'))
{
	header('HTTP/1.0 403 Forbidden');
	die('403: Forbidden');
}

Or use this for ColdFusion:

<cfif structKeyExists(cgi,"HTTP_X_MOZ")>
	<cfif cgi.HTTP_X_MOZ EQ "prefetch">
		<cfheader statuscode="403" statustext="Forbidden" />
		<cfabort />
	</cfif>
</cfif>

Comments


Comments are now closed for this entry.