Detect Google Chrome page prefetch Detect Google Chrome page prefetch google-chrome google-chrome

Detect Google Chrome page prefetch


It appears that this is undetectable server side.

An issue was opened for this for the Chromium project. It's marked as "won't fix" (Prerendering does not have any distinguishing HTTP headers). The prefetch request doesn't show up in the Dev Tools "Network" tab, so you can't easily confirm this by look at the headers. I checked them using Wireshark, and unfortunately there was no difference distinguishing pre-render requests from "normal" requests.

Workaround:

You can check for prefetched pages client-side using the Page Visibility API. It's a bit more work than server side tracking, but you can insert a script tag in your page that checks if it's a prerender request. If that's the case, send an AJAX request which somehow identifies which page it was, and use that to increment the counter in your database.

if (document.visibilityState !== 'prerender'){    //ajax call registering page hit}

Just watch out that the AJAX request doesn't return a result from cache, preventing it from arriving at the server.