Phil Wallach

I follow where my mind leads …

Phil Wallach header image 2

OpenLaszlo: background loading of images

August 1st, 2007 · No Comments · OpenLaszlo

Some discussion in the OpenLaszlo Forums gave me an idea for improving the performance of the deferred image loading in OpenLaszlo: optimising for a large number of views.

The idea is quite simple; if the views are being initialised in idle time (through initstage=”late”), then load the image when the view is initialised, that is in the “oninit” handler.  The application will continue initialising views and loading images in the background, while the application is running.

<class name="myclass" oninit="this.load_image()">
    <attribute name="imageurl" type="string" />
    <method name="load_image">
      var image = this.datapath.xpathQuery("text()");
      if (image == null) return;
      var imageurl="images/" + image;
      if (this.getAttribute('imageurl') == imageurl)
        return;
      this.setSource(imageurl);
      this.setAttribute('imageurl', imageurl);
    </method>
    ...
</class>

...

<myclass name="myview" initstage="late" />

References

The enhanced class applies to the code in OpenLaszlo: optimising for a large number of views.  In that post the code example used initstage=”defer”, which delays instantiation until completeInstantation() is called.  For background image loading to work, you must use initstage=”late” instead of “defer”.

Tags:

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment