A Lazy Javascript, a Ruby Load and a Sponge plugin to a bar

March 21, 2008

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.


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!'

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 »


Up all nite with the sponge

November 15, 2006

Every developer have been up all night doing something completely ridiculous: forgetting a semi-colon and screwing your JS compression, writing hot new code for your acts_as_idiot functionality that unbeknownst to you the RoR team has already implemented and included in the latest version. Once in the C++ days I even forgot a bracket and to deallocate memory. Regardless, there are so many tricks I wish I knew before I was up all night with the sponge.

Let’s take our kimonos off and run around naked. I will show you mine if you show me yours.Kimono
Read the rest of this entry »