I recently received a request to determine if a user's browser has pre-fetching enabled. I've searched around, but I've come up empty. Any thoughts on how to accomplish this task? I've watched traffic in the header and I don't see anything in the request that would开发者_运维问答 indicate pre-fetching has been enabled.
Put <link href="myTester.xxx" rel="prefetch" />
in the head.
In whatever handles for myTester.xxx (which would hence more likely by myTester.php, myTester.aspx, etc.) set a flag in the session (if you're already using sessions and hence there's no more penalty for doing so) or set a cookie. Make the response v. small (empty would be fine).
On onload, set a delayed (use setTimeout
) attempt to retrieve an XML or JSON file from myTesterResult.xxx which has a different result depending upon that session value or cookie.
Alternatively, if you don't need it to be reacted to on that page, there's no need for any client-side script at all, subsequent server-side script will be able to use the session or cookie as appropriate.
I'll 2nd the opinion that the client probably can't do it. One possible solution is to add a prefetch to a page that signifies pre-fetching is enabled, e.g.:
<link rel="prefetch" href="/hasPrefetching.php">
If you need to know on the server, you now have the info. If you need to know on the client, you can poll for it after a while.
精彩评论