Question

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.)

Was it helpful?

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.

OTHER TIPS

This question is very similar to "How to detect if cookies are enabled?". But you must use client-side redirection, because prefetched page start loading after loading main page.

Directly prefetch request can by detected by header (X-Moz: prefetch for FF) or by passing additional param to a link.

P.S. Without cookies enabled you cannot detect it for client, only for each directory prefetch request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top