Is it possible to stop Chrome and other browsers from pre-fetching/rendering my site?
Chrome and Safari send an X-Purpose: preview
HTTP header when pre-fetching/rendering web content. [Source]
Firefox sends a similar header called X-moz: prefetch
. [Source]
To block pre-fetching, you could return a 404 response when such headers are detected, as suggested by Peter Freitag in this blog post. He recommends adding these lines to .htaccess
to block Firefox prefetching:
RewriteEngine On
SetEnvIf X-moz prefetch HAS_X-moz
RewriteCond %{ENV:HAS_X-moz} prefetch
RewriteRule .* /prefetch-attempt [L]
You can extend this to block Firefox, Safari, and Chrome prefetching like this (untested, but should work):
RewriteEngine On
SetEnvIf X-moz prefetch HAS_preview
SetEnvIf X-Purpose preview HAS_preview
RewriteCond %{ENV:HAS_preview} .
RewriteRule .* /prefetch-attempt [L]
Google Chrome does not send any special headers to prerender requests anymore. See:
- https://code.google.com/p/chromium/issues/detail?id=86175
- https://github.com/nickhsharp/prefetchNightmare