[Project_owners] Image prefetching

Babak Esfandiari babak at sce.carleton.ca
Thu Mar 31 12:43:40 EST 2005


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.


More information about the Project_owners mailing list