[Project_owners] Image prefetching

Konstantin Svist fry.kun at gmail.com
Thu Mar 31 12:32:18 EST 2005


There are several ways, I'm pretty sure I don't even know them all :D
I don't know which way AdBlock does it...

few of the ways would be
* setting the src attribute to something nonexistent, e.g. blank string
* removing the img element from the document tree

HTH
~Konstantin


On Thu, 31 Mar 2005 12:43:40 -0500, Babak Esfandiari
<babak at sce.carleton.ca> wrote:
> 
> Speaking of which, is there a simple way to prevent an image from being
> loaded at all? I just can't seem to figure out how AdBlock does it by
> looking at its code. The old version of AdBlock (which code I do
> understand at least!) used:
> 
> style.display = "none";
> 
> which only hides the image after the fact.
> 
> Thanks,
> 
> Babak.
> 
> 
> Konstantin Svist wrote:
> > WOW, that actually works!
> > I've been looking for a way of hooking something up to imageloads...
> > strangely enough, tmpImage.onload = 'alert()' will not work at all...
> >
> >
> > Anyway, your problem is very simple - some of your images load BEFORE
> > your JS even gets to tmpImage.setAttribute(...). And since the image
> > is already loaded, the onload event will not be fired.
> > To fix it, swap that line with the previous one:
> >      for ( ... )
> >      {
> >          var tmpImage = new Image();
> >          // This is only for testing purpose
> >          tmpImage.setAttribute("onload", "alert(this.src);");
> >          tmpImage.src = ...;
> >      }
> >
> >
> >
> > cheers,
> > Konstantin
> >
> >
> > On Thu, 31 Mar 2005 11:29:56 +0200, Luca Minuti <lithian at tiscalinet.it > wrote:
> >
> >>Hi,
> >>
> >>I need to pre-load some images in my firefox extension. Now I have
> >>a code like this:
> >>
> >>    for ( ... )
> >>    {
> >>        var tmpImage = new Image();
> >>        tmpImage.src = ...;
> >>        // This is only for testing purpose
> >>        tmpImage.setAttribute("onload", "alert(this.src);");
> >>    }
> >>
> >>but with this code I see the alert only for a small amount of images.
> >>I'm trying to understand how to use the caching system of firefox in a
> >>more direct way (perhaps with the cache-service component), but
> >>without success.
> >>
> >>Any one can help me?
> >>
> >>Thanks, Luca.
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org 
> http://mozdev.org/mailman/listinfo/project_owners 
>


More information about the Project_owners mailing list