Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I know you can guide Chrome to prefetch links you think users are likely to click on your site, but can you also do the inverse? Can you tell Chrome (or really any browser) not to prefetch and prerender your site?

Is there a tag or other way I can tell browsers that pre-fetching links from the currently viewed page shouldn't be done?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.