Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP header to detect a preload request by Google Chrome

Google Chrome 17 introduced a new feature which preloads a webpage to improve rendering speed upon actually making the request (hitting enter in the omnibar).

Two questions: Is there a HTTP header to detect such a request on server side, and if one actually exists what is the proper response in order to prevent such preloading (to prevent unintended requests which might have unwanted effects)?

Does Google Chrome check the robots.txt before making preload requests? Is there a robots.txt setting which targets only this specific behaviour? (I supose/hope disallow already works).

Is there a meta tag to inform Google Chrome to never preload again on the current domain?

like image 525
Tiberiu-Ionuț Stan Avatar asked Mar 24 '12 13:03

Tiberiu-Ionuț Stan


People also ask

How do I see HTTP headers in Chrome?

To view the request or response HTTP headers in Google Chrome, take the following steps : In Chrome, visit a URL, right click , select Inspect to open the developer tools. Select Network tab. Reload the page, select any HTTP request on the left panel, and the HTTP headers will be displayed on the right panel.

How do I preload in Chrome?

From the Chrome app, tap the Menu icon (at the upper-right corner of the screen)> Settings > Bandwidth management. Tap Preload webpages. Select an option: Always: Chrome will preload webpages no matter how you're connected (e.g., mobile data, Wi-Fi, etc.).


2 Answers

When Firefox pre-fetches content (at the behest of the referrer page’s markup), it sends the following header with the request: X-moz: prefetch

Safari does similarly, using: X-Purpose: preview. According to this ticket , Chrome does, too.

For pre-rendering, Chrome does not send any header whatsoever to the client. Instead, one must use the Page Visibility API, in JS

source, additional reading

like image 105
abraham Avatar answered Oct 11 '22 09:10

abraham


Chrome stopped sending X-Purpose header in 2011 and they stated that they won't fix it there: https://code.google.com/p/chromium/issues/detail?id=86175.

They re-introduced sending Purpose:prefetch headers with all nostate-prefetch requests back in 2018 as stated by the last comment on this issue. https://bugs.chromium.org/p/chromium/issues/detail?id=86175#c65

like image 33
hawk Avatar answered Oct 11 '22 10:10

hawk