# Lazy loading of scriptaculous

**URL:** <https://www.ruby-forum.com/t/lazy-loading-of-scriptaculous/91076>\
**Category:** Rails\
**Created:** [April 4, 2007, 11:45am UTC](https://www.ruby-forum.com/t/lazy-loading-of-scriptaculous/91076 "2007-04-04T11:45:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [April 4, 2007, 11:45am UTC](https://www.ruby-forum.com/t/lazy-loading-of-scriptaculous/91076/1 "2007-04-04T11:45:11Z")

</div>

Hi \*, both scriptaculous and prototype are quite big, and I don’t use  
all the goodness inside there, including :defaults is a bit too much  
for me.  
Someone knows of a way to dynamically load what’s effectively used  
inside a side ?  
It would be a great feature …

ngw

–  
Nicholas W.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [April 4, 2007, 3:04pm UTC](https://www.ruby-forum.com/t/lazy-loading-of-scriptaculous/91076/2 "2007-04-04T15:04:13Z")

</div>

Do you mean load dynamically on the client side?

If so, can’t say i’ve heard any tricks to achieving this, what you  
could do is compress the files, this will help reduce the size. Also  
I was under the impression that by default most browsers cache  
javascript so I guess you could see it as just the one download. But i  
could be wrong. Hope this helps

Also if you choose a different javascript library consider moo tools  
which allows you to choose only options you want.

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [April 4, 2007, 3:24pm UTC](https://www.ruby-forum.com/t/lazy-loading-of-scriptaculous/91076/3 "2007-04-04T15:24:58Z")

</div>

I came across this a while ago, I was already loading javascript details  
and  
then  
added mapping code as well. I was using Virtual Earth maps as Google  
Maps  
are crap for  
Ireland.

In order to only have one layout file but still only load the mapping  
code  
on the pages where  
I need it, I added an \<%= @mapcode -%\> to the layout.

Then in my controller I can only set the @mapcode when I want it set.

@mapcode = get\_mapcode

private

def get\_mapcode

code = " \<script src="  
[http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js\“\>\</script\>”](http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js%5C%22%3E%3C/script%3E%22)

end

Not quite what you are looking for but it does the trick for me.

Keith
