# Best practice for showing ajax loader gif?

**URL:** <https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839>\
**Category:** Rails\
**Created:** [April 15, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839 "2008-04-15T15:35:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [April 15, 2008, 3:35pm UTC](https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839/1 "2008-04-15T15:35:38Z")

</div>

what is the best practice for showing animated ajax spinner?

The usual Element.show(‘spinner’) has to stick with every form’s  
:loading. Is there some easier or light-weight method?  
Because I have this page that can contain upto 100 forms. And with all  
of those would be 100 hidden spinners.

Please suggest something.

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [April 15, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839/2 "2008-04-15T15:39:41Z")

</div>

On 15 Apr 2008, at 14:35, Vapor … wrote:

> what is the best practice for showing animated ajax spinner?
> 
> The usual Element.show(‘spinner’) has to stick with every form’s  
> :loading. Is there some easier or light-weight method?  
> Because I have this page that can contain upto 100 forms. And with all  
> of those would be 100 hidden spinners.

Depends on whether you need 1 spinner per form or a single page  
spinner (since in the first case if you have 100 different spinners  
those do have to be created somehow).  
You may want to have a look at Ajax.Responders  
(100 forms on a page doesn’t sound like a great idea)

Fred

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [April 15, 2008, 3:45pm UTC](https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839/3 "2008-04-15T15:45:20Z")

</div>

> Depends on whether you need 1 spinner per form or a single page  
> spinner (since in the first case if you have 100 different spinners  
> those do have to be created somehow).

I spinner per form.

> (100 forms on a page doesn’t sound like a great idea)

True, but each form just contains a single field. And is in the  
requirements. So have to do it anyway.

I read somewhere about giving CSS class name to DOM. Class definition  
contains an animated gif. So you can call it from anywhere with  
.addClassName . I tried but didnt work properly for me.

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [April 15, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839/4 "2008-04-15T15:54:01Z")

</div>

On 15 Apr 2008, at 14:45, Vapor … wrote:

> requirements. So have to do it anyway.  
> There is such a thing as a badly designed requirement 🙂
> 
> I read somewhere about giving CSS class name to DOM. Class definition  
> contains an animated gif. So you can call it from anywhere with  
> .addClassName . I tried but didnt work properly for me.

Sounds like a plan, although depending what element you call this on  
it might not look like you want. I’d try setting all this up on a  
simple test page to get the basics working and only then try and apply  
it to the 100 form monster.

Fred

---

<div class="post-metadata">

**Author:** ![vapor](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/5e9695/32.png) [@vapor](https://www.ruby-forum.com/u/vapor)\
**Post date:** [April 16, 2008, 12:19am UTC](https://www.ruby-forum.com/t/best-practice-for-showing-ajax-loader-gif/134839/5 "2008-04-16T00:19:21Z")

</div>

Using classes is the way to go, because the image is only loaded once  
and applied to all elements that have the class.

you can use this javascript to change a class:

onclick=“Element.extend(this).addClassName(‘loading’)”

make sure that applying your class looks right in the first place! the  
way I’d do this is to apply that class to the element by default, then  
remove it when you’ve got it looking right and put the javascript in.  
also make sure that your css that applies to the class loading is  
below any of the other css that applies to this element, or it will be  
over ridden.

On Apr 16, 1:52 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
