[Greasemonkey] add prefetch attributes

Nikolas Coukouma lists at atrus.org
Mon May 16 15:14:06 EDT 2005


chris feldmann wrote:

> " I have no idea how I can confirm whether Firefox is prefetching or not."
>
> Sounds like yet another perfect use for the Live HTTP Headers
> extension: http://livehttpheaders.mozdev.org.
> <http://livehttpheaders.mozdev.org>

That doesn't seem likely to indicate prefetching, but maybe I'm just not
seeing it.

I'd just use Ethereal or some other packet capture tool.
http://www.ethereal.com/

-Nikolas Coukouma

>     Thanks a lot!
>
>     By patching together pieces of other scripts, I was able to add the
>     prefetch attribute (though I just did link.rel="prefetch" and used a
>     loop instead of a getbyId since I don't think it has an ID).
>
>     What you say about it being too late makes a lot of sense - I have no
>     idea how I can confirm whether Firefox is prefetching or not. Testing
>     it is difficult as the web site I'm going to (TWOP) is reporting back
>     a lot of dropped connections with or without my script :(.
>
>     I'll try both the xmlhttprequest and the other way and see if I can
>     get it to make a difference.
>
>     Thanks again.
>
>     On 5/16/05, Nikolas Coukouma < lists at atrus.org
>     <mailto:lists at atrus.org>> wrote:
>     > Leo Zelevinsky wrote:
>     >
>     > >Thanks!
>     > >
>     > >The script is quite different than what I was envisioning though -
>     > >what it seems to do is preload an image, after determining the
>     image
>     > >path.
>     > >
>     > >What I am thinking of doing is not handling any of the prefetching
>     > >itself - let Firefox do it, but just to alter the settings on
>     the link
>     > >to add the prefetch attribute.
>     > >
>     > >I guess if that's hard to do for some reason I could try to use
>     > >GM_xmlhttpRequest instead.
>     > >
>     > >And the pages I'm preloading aren't images anyway, though
>     certainly
>     > >the idea of preloading the image is very useful too.
>     > >
>     > >Thanks again though - any help on altering an element in the way I
>     > >want appreciated (I'm currently reading the 'Diving into
>     greasemonkey'
>     > >book - so maybe that will answer my questions as well.
>     > >
>     > >
>     > You can add " prefetch" to rel, but I doubt Firefox will act on
>     it. The
>     > page is already half-loaded by the time your script gets to it.
>     Using
>     > GM_xmlhttpRequest is the best way to go. Dive into Greasemonkey
>     and the
>     > Greasemonkey homepage have documentation for it. Basically, all
>     you need
>     > to do is:
>     > GM_xmlhttpRequest({ url: " http://something", method: "get" });
>     > Normally you'd set handlers for when the data arrives, but that
>     doesn't
>     > matter since you just want the request to be made.
>     >
>     > As for modifying elements, you can usually do:
>     > var elm = document.getElementById( "something" );
>     > elm.attr = "value";
>     >
>     > for example,
>     > elm.rel += " prefetch";
>     >
>     > The DOM way of doing this is using hasAttribute, getAttribute,
>     setAttribute:
>     > elm.hasAttribute( "rel" ); // does it have a rel attribute?
>     > var str = elm.hasAttribute( "rel" ); // get the current value of rel
>     > elm.setAttribute( "rel", str + " prefetch" ); // set the value
>     of rel
>     >
>     > There's a lot more. You can read the W3C's DOM spec, or check
>     out XUL
>     > Planet's reference
>     > http://xulplanet.com/references/objref/
>     >
>     > -Nikolas Coukouma
>     >
>     > >On 5/16/05, Julien Couvreur <julien.couvreur at gmail.com
>     <mailto:julien.couvreur at gmail.com>> wrote:
>     > >
>     > >
>     > >>Sure, there is a script that does that already for the
>     AppleGeeks site:
>     >
>     >>http://www.warwick.ac.uk/~esudbi/greasemonkeyscripts/applegeeks_preload.user.js
>     <http://www.warwick.ac.uk/%7Eesudbi/greasemonkeyscripts/applegeeks_preload.user.js>
>     > >>
>     > >>Besides looking for links that say "next", you could also look
>     for rel="next"
>     > >>
>     > >>Cheers,
>     > >>Julien
>     > >>
>     > >>On 5/16/05, Leo Zelevinsky <leo.zelevinsky at gmail.com
>     <mailto:leo.zelevinsky at gmail.com>> wrote:
>     > >>
>     > >>
>     > >>>Hi all!
>     > >>>
>     > >>>I would like to take advantage of the prefetch feature of
>     firefox on
>     > >>>non-prefetch-aware webpages. Can I use Greasemonkey for this?
>     I did
>     > >>>some searches with no luck.
>     > >>>
>     > >>>It seems like it should be relatively straightforward so I'm
>     wondering
>     > >>>why I can't find anything. For instance, I'd want to add to a
>     link
>     > >>>that says "Next" the prefetch attribute automatically.
>     > >>>
>     > >>>Any pointers would be much appreciated. Thanks!
>
> On 5/16/05, *Leo Zelevinsky* <leo.zelevinsky at gmail.com
> <mailto:leo.zelevinsky at gmail.com>> wrote:




More information about the Greasemonkey mailing list