cre8d design - clean, clear, creative websites
  • Latest
  • Highlights
  • Discussions
  • Blogging
  • Design
  • Ebooks / Books
  • Social Media
  • Personal
  • About
  • Portfolio
  • Services
  • Blog
  • Contact
  • Twitter
  • Facebook
  • RSS

WordPress rel="next" causes issues in Firefox

Posted by Stephen Merriman on October 20, 2010

Recently I spent quite a long time tracking down a very unusual bug on a WordPress site I was coding up. I had installed the very handy WP-PostViews plugin, and was double checking I had installed it correctly by loading a post and watching the post counts go up.

Yet the strangest thing was happening – not only would the post I was currently viewing increase, but another post had its count going up as well!

Several hours’ debugging later I noticed the problem was only happening in Firefox, and narrowed down the problem, confirmed by another Web Developer’s blog post. WordPress by default adds various lines of code into the header of your website, including <link rel="prev"...> and <link rel="next"...> links, pointing to the previous and next blog entry from the one you are viewing. As of Firefox 3.5, anything found in a <link rel="next"...> tag will automatically be “prefetched”.

The benefits? If a user is browsing through several blog posts, the posts will appear to load much faster than normal (as Firefox has already downloaded it for you).

The downsides? Nearly everything else. The WP-PostViews will have inaccurate post counts. Other forms of tracking may also be affected (though javascript-based tracking methods like Google Analytics are not affected). Sites with a huge number of visitors where any performance optimisation is vital are badly affected – the load on your server is doubled when viewing a single post. Could there be side effects with caching plugins? Perhaps. And I’m sure the list goes on.

The solution? Simple – just add the following code to your functions.php theme file:

remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

or, for a version of WordPress before 3.0:

remove_action('wp_head', 'adjacent_posts_rel_link');

I will be doing so for all websites from this point onwards.

The lifespan and depth of tweets vs blog posts
Are blogs still an afterthought?
  • http://www.mattb.net.nz/ Matt Brown

    Simply disabling the plugin is a bit short-sighted. Prefetching has huge benefits for the end users and should be encouraged.

    If you’re concerned about your page-views being impacted you can simply ignore all requests coming in with the X-moz: prefetch header

  • Stephen

    Sure; and if I wrote the plugin myself I would definitely do that. Yet I would still disable prefetching the ‘next’ blog post on virtually all of the sites I’m working on, as a small performance increase on the off chance that a user decides to visit the next blog post shortly doesn’t come close to outweighing the performance hit on the server itself.

    While prefetching is certainly a good idea in some scenarios, I would also consider having it on by default in all WordPress blogs without any thought is also a little ‘short-sighted’. It depends on the website itself, and certainly should be off (at least in the ‘next blog post’ setting) in a large number of cases.

  • http://www.noosawebdesign.com.au Dave Spencer

    This is a very bad thing if you run code in your pages (shortcodes, that do things when the page is accessed, for example). Having them randomly execute out of their normal logical sequence (completely unbeknows to the unwitting coder) can cause severe embafflement. A whole day, pretty much … :(

    Sorted now tho, thanks to this and other posts

  • Alex

    thank you! had the same problem here but now it’s solved^^

  • bo

    thx.. took me 4 hours to debug this problem … then I found this post…

Hi, I'm Rachel Cunliffe!

Looking for a blog designer, Wordpress expert, website designer, or want to find out how I can help you? I'd love to hear from you.

Email:
rachel@cre8d-design.com
Phone:
(US) 646 233 3046
(NZ) 027 3833 746
Skype:
rachelcunliffe

Keep updated

Get blog posts via email

Follow @cre8d