Search code examples
phpapacheprefetch

How to detect prefetching from the browser in PHP?


Some pages can be prefetched by the browser (see this or that). How to detect in PHP that a request is a prefetched request ?

Is there any method is not browser-specific ?

(PS: I use Apache.)


Solution

  • I was looking for a similar answer to stop FF and other browsers throwing out my server side page counts.

    According to the articles above, Firefox sends a header which makes it easy to detect but the Chrome white paper states that Chrome doesn't give any indication to the server. The Chrome white paper notes that external analytic solutions (scripts written in JS) will not count the prefetch hits when they use the page visibility API.

    My suggestion is to write your own JS script to detect if the page is ever made visible.