2

I am saving the post->ID in a session array to keep a history of the accessed pages for a specific custom post type. This code was added to that specific custom post type's template, so that the session data only updates for requests for this type.

So, if the user loads the page with postID 1, then "1" is saved in the session. If he then loads a page with postID 5, then "5" is added to the session, resulting in array(1, 5), and so on.

This works just fine across all major browsers with the exception of FireFox (Windows & Mac). For some reason the initial session is saved properly, but the next time I reload the same page, it will suddenly show for example array(1, 5) even though only postID 1 was accessed.

I added logging to the script to log whenever the session data gets updated and that's when I noticed that for some reason FireFox sends like a partial request (faster than full page load) before loading the actual post, e.g.:

  1. user loads page with postID 1, session gets updated with array(1)
  2. user hits reload, FireFox loads postID 5 and then loads postID 1 again, resulting in array(1, 5)

This extra page load is not visible and also doesn't show in Firebug, but somehow FireFox sends those multiple page requests even when just reloading a single page.

I have already ruled out the code, since it's working fine in all other browsers and I also disabled all plugins/addons but it still happens even in vanilla FireFox. Plus it's cross-platform, so happens on a mac & windows PC when using FireFox.

Has anyone experienced a similar issue before?

3
  • Of course, right after submitting it I find out the cause for the issue: The problem is caused by FireFox prefetching the other post in the background, resulting in those noticed 2 different postIDs per single page request. If I disable prefetching, then it behaves as expected, so will need to add code to check for the prefetch header sent by FireFox and avoid updating the session data in such a case. For more info on FireFox's prefetch, see here: developer.mozilla.org/en/Link_prefetching_FAQ
    – ShuQi
    Jan 26, 2012 at 16:55
  • 2
    You should add your comment as an answer, so that you can accept it as correct. Jan 26, 2012 at 17:08
  • Not sure it helps, I used that bit of code into functions.php remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
    – Simon
    Jan 26, 2012 at 18:34

1 Answer 1

3

Of course, right after submitting it I find out the cause for the issue:

The problem is caused by FireFox prefetching the other post in the background, resulting in those noticed 2 different postIDs per single page request.

If I disable prefetching, then it behaves as expected, so will need to add code to check for the prefetch header sent by FireFox and avoid updating the session data in such a case.
For more info on FireFox's prefetch, see here: http://developer.mozilla.org/en/Link_prefetching_FAQ

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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