JQuery plugin for lazy loading / lazy evaluation?

Is there such a jQuery plugin?

More specifically: I want to use some elegant and simple way to delay code execution until it is needed (some kind of event happens). And when this event occurs, the delayed code should be executed only once. Some lazy initialization.

For example, apply some animation to an element when the document is not ready, but when the user is hovering over that element.

I know how to do this manually, but I don’t like it, because I should think about checking and setting the “initialized” flag before performing an anonymous function. I was wondering if this has already been done (mistake without any tasty features).

+4
source share
3 answers

http://plugins.jquery.com/project/LazyReady

Lazy Ready Plugin designed to delay initialization of the code until the specified DOM element interacts with (hanging / focused).

+4
source

Lazy Load does lazy loading of images.

+2
source

Answer a more specific question:

Don't you really need a plugin? Just do something in that direction.

This will call the postponedHeavyFunction() function only after the user clicks on the element with id lazyelement and only once.

 function postponedHeavyFunction() { // unbind. This guarantees that postponedHeavyFunction will only // execute once for the event we bound it to #lazyelement $("#lazyelement").unbind('click', postponedHeavyFunction); ... //do whatever .... } //when event is triggered the function you specify gets run $("#lazyelement").bind('click', postponedHeavyFunction); 

Check out http://jsbin.com/agora/ for a deadly silly demo.


What exactly do you want. What should be lazy loaded / lazy? Be more specific.

Lazy evaluation (as is known from other languages) AFAIK is not supported in Javascript per se (as a language concept). Except, perhaps, for operators such as & , | , && , || .

If you just want some javascript to be lazy to load other scripts, take a look at this: Riskless lazy JavaScript loading with LazyLoad

+2
source

All Articles