Lazy Load Content
Sometimes a portion of your page takes a really long time to generate and render. Instead of allowing the user to spin his thumbs, you can display the bulk of content to user and send off a separate ajax request to gather the “slow” data. Lazy Load Content makes late loading a portion of your page through ajax as easy as setting up a remote_function call. With options to render fragment cached if they exist, and perform the late load if not, your app will fly like the sloth eating eagle.
Install
ruby script/plugin install http://arperftoolkit.rubyforge.org/svn/trunk/lazy_load_content/
Copy the file javascripts/lazyLoadContent.js into your public/javascripts folder and include it with prototype.js in your views.
The Basics:
In your rhtml or haml file:
<h1> I love giraffes.. basically </h1> <% lazy_load(:remote => {:update => 'lazyLoadContent', :url => {:action => 'lazy_load_action'}})do -%> <div id = "lazyLoadContent"> We wait while the giraffes are smelling themselves. </div> <% end -%>
In your controller define the specified function
def lazy_load_action render :text => 'The giraffes are ready!' end
When the page loads, the loading text is displayed: We wait while the giraffes are smelling themselves.
Then after the ajax call we see: The giraffes are ready!
…….. and more………. Read the rest of this entry »