Slowing Down jQuery

Sep 5th, 2011

I wanted to work on adding a nice ‘loading…’ effect to my application,
of which I have little access to its server code. I needed to find a way
to slow down my AJAX calls, so I can see the effect and tweak it in my
browser.

Unfortunately, AJAX is too fast on a local environment, and I couldn’t
find anything about slowing jQuery down (all Google found were ‘jQuery
script too slow’ question pages).

Fortunately, a co-worker and I figured that we could take advantage of
the new jQuery Deferred
objects.
I added this line to a function that wraps AJAX calls:

And it worked like magic.

It merges the original AJAX’s promise along with something that takes
time (i.e. the 3s fadeOut animation), and then uses a deferred
pipe to make the promise only
return the original AJAX result.