Wednesday, May 06, 2009

Cool jQuery trick. Or why it pays off to know how things really work

So we have this search against a CRM provider which could have been a lot faster, to say the least. It’s just that we don’t know if this CRM is inherently slow, or us who are inherently incompetent.

Anyways, when we can’t speed things up, we give the user a slightly better experience like an animated dog jumping around, or the more professional spinner.

This being a web application, I dreaded this task. I really didn’t want to change a well functioning search form (except for the lack of speed) into a conglomerate of ajax calls and dom manipulations. Luckily, a coworker volunteered.

Today he asked for a review. Browsing his code, I noted he had begun his journey down that dreaded path. Then we had a moment of insight:

“This is a regular post, right? And the browser will get nothing in return until the search is done, yes?

So all we need is to show that flashy spinner while we wait for the results.

Why not use jQuery to hook up the proper event and make the spinner visible when we post?”

And so we did:

$(“#submitButton”).click( function() { $(“#spinner”).show(); } );

Works like a breeze. At least in Firefox.

No comments: