This project is read-only.

jQuery.inMemoryImageLoader = function(strURL, intMaxWaitMilliseconds, callbackFunction)

Loads an image in memory then returns the image (or null) via a callback function.


$.inMemoryImageLoader("graphics/logo.png", 30000, function(loadedImage) {
	if (loadedImage) {
		// Now that the image has been loaded, you can assign it
		// as the source of an image element, size the element, etc.
	} else {
		// Perhaps there is a default image you can use if the
		// selected one didn't load.


  • strURL - The URL of the image to load.
  • intMaxWaitMilliseconds - The maximum number of milliseconds to wait before deciding that the image load has failed in case the error event is never raised.
  • callbackFunction - The function to call when the image finishes loading or fails to load. Must take a single argument that is the image  element (not a jquery element) or null if the load fails.


The code attempts to use the load and error events for an image. These sometimes do not fire, though. So, the backup plan is to poll for the image to see if it ever loads and to have the maximum wait time before deciding to give up.

Last edited Jul 10, 2012 at 4:03 AM by cmaterick, version 6


No comments yet.