[OpenLayers-Dev] Loading img with Ajax to be able to cancel
ahocevar at opengeo.org
Mon Mar 19 03:27:42 EDT 2012
loading raw image data with Ajax requires client-side Base64 encoding
to create a data URI, which would be very expensive. And IE has only
started supporting data URIs properly in version 9. So this is not an
option for most users who are still on IE <= 8. Another way to be able
to abort image loading is to load each image in a separate IFrame. The
problem here is that depending on the cache settings of the image, it
would be loaded again when you move it from the IFrame to your DOM. So
using a Canvas would be the only way to do this, which is also not
supported in IE < 9.
BTW, which version did you use for your tests? Because tile loading
has seen a major rewrite between 2.11 and now.
On Mon, Mar 19, 2012 at 5:48 AM, Tim-Hinnerk Heuer <th.heuer at gmail.com> wrote:
> Just wondering here how one could optimize the img loading of OpenLayers:
> Would it be possible to load img srces with ajax and then assign the .src
> attribute on the <img/> element? That way it would be possible to cancel the
> loading of an img before it gets added to the dom and only render and
> therefore finish loading it if the user does not pan away from it.
> Not sure if this is already happening, because I haven't checked, sorry.
> I was stress-testing our applications with Chrome's profiler and the set src
> function was a significant candidate for optimization, because it seemed to
> be one of the heavier used functions up there with the anonymous function
> call inside the Util.bind function.
> Also, I noticed that if one zooms and pans about a lot, after a while one
> gets white tiles and it seems like things are broken. Waiting for quite a
> bit revealed that the requests must have been running in the background and
> when they were finished the imgs were displayed. If we can cancel the img
> loads that are not within the current extent, we would probably save a lot
> of WMS requests to the server.
> Does this sound sensible?
> ++Tim Hinnerk Heuer++
> Twitter: @timhheuer
> Blog: http://www.thheuer.com
> Dev mailing list
> Dev at lists.osgeo.org
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Dev