Hack #52. Prefetch Yahoo! Search Results
Automatically prefetch and cache the first search result on Yahoo! Web Search.
If you know how to use them properly, search engines are pretty darn good at finding exactly the page you're looking for. Google is so confident in its algorithm that it includes a hidden attribute in the search results page that tells Firefox to prefetch the first search result and cache it. You're probably going to click on the first result anyway, and when you do, it will load almost instantaneously, because your browser has already been there.
Yahoo! Web Search is pretty good, too, but it doesn't yet have this particular feature. So let's add it.
There are two important things about Yahoo! search results that you can discover by viewing the source on its search results page. First, the links of the search results each have a class yschttl
. Yahoo! uses this for styling the links with CSS, but you can use it to find the links in the first place. A single XPath query can extract a list of all the links with the class yschttl
, and the first one of those is the one we want to prefetch and cache.
The second thing you need to know is that the search results Yahoo! provides are actually redirects through a tracking script on rds.yahoo.com that records which link you clicked on. A sample link looks like this:
http://rds.yahoo.com/S=2766679/K=gpl+compatible/v=2/SID=e/TID=F510_112/ l=WS1/R=2/IPC=us/SHE=0/H=1/SIG=11sgv1lum/EXP=1116517280/*-http%3A//www.gnu. org/licenses/gpl-faq.html ...
Get Greasemonkey Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.