[Developers] mjt firefox attempting to load img src

Nick Thompson nix at metaweb.com
Wed Aug 8 19:30:50 UTC 2007


Geoff Smith wrote:
 > I've noticed that firefox (maybe other browsers too - i've not checked)
 > attempts to load and image in this type of structure:
...
 >         <img src="${o.src}"/>

yes, good tip - if you have a tag like <img src="$some_expression"> the
browser will treat it literally and try to fetch an image before mjt gets
a chance to substitute in the real url.  mjt.src="$some_expression" will
hide the src attribute from the browser until mjt expands it.
you may still want to include a src="#" attribute with your img tag so that it
validates as xhtml.  the src= will be overridden by the mjt.src="..." when
the template is expanded.

the other place where mjt.src= comes in useful is with the <iframe> tag,
which has the same issues as <img> as far as the browser trying to interpret
the src= attribute before we're ready.

 > I also have a question, are there other attributes which could cause
 > similar performance problems? I.e. could using class instead of
 > mjt.class cause the browser to do some unnecessary work when it loads
 > the page?

computing other attributes might be slightly slower, but i doubt it's
significant.  mjt.src= is definitely worth using because an extra
network request is comparatively expensive.  but it shouldn't be a
noticeable performance hit for the browser to keep around a few extra
attributes that were only used in the template source code.

     nick

Geoff Smith wrote:
> Hi,
> 
> I've noticed that firefox (maybe other browsers too - i've not checked) 
> attempts to load and image in this type of structure:
> 
> <div id="template" style="display:none">
>     <div mjt.def="mkexample(o)">
>         <img src="${o.src}"/>
>     </div>
> </div>
> 
> It attempts to load a file called ${o.src}... I would have thought the 
> display:none would have taken care of that, guess not. The solution is 
> to use mjt.src instead of just src. I thought I would point it out as 
> this kind of thing could easily not be noticed - it makes the page load 
> more slowly and hits the server unnecessarily.
> 
> I also have a question, are there other attributes which could cause 
> similar performance problems? I.e. could using class instead of 
> mjt.class cause the browser to do some unnecessary work when it loads 
> the page?
> 
> Thanks!
> 
> Geoff
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers


More information about the Developers mailing list