# Javascript include in html - load times

**URL:** <https://www.ruby-forum.com/t/javascript-include-in-html-load-times/95733>\
**Category:** Rails\
**Created:** [June 11, 2006, 3:35pm UTC](https://www.ruby-forum.com/t/javascript-include-in-html-load-times/95733 "2006-06-11T15:35:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kfir\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e47c2d/32.png) [@Kfir\_L](https://www.ruby-forum.com/u/Kfir_L)\
**Post date:** [June 11, 2006, 3:35pm UTC](https://www.ruby-forum.com/t/javascript-include-in-html-load-times/95733/1 "2006-06-11T15:35:23Z")

</div>

Hi,  
If I include a javascript library, will it load when the html load, or  
just at the first use?  
I have table.js and I have few pages that needs it.  
Should I include it just on the pages that needs it, or put it on the  
application\_layout?

Thanks,  
Kfir

---

<div class="post-metadata">

**Author:** ![Kfir\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e47c2d/32.png) [@Kfir\_L](https://www.ruby-forum.com/u/Kfir_L)\
**Post date:** [June 11, 2006, 5:04pm UTC](https://www.ruby-forum.com/t/javascript-include-in-html-load-times/95733/2 "2006-06-11T17:04:33Z")

</div>

Thanks,  
I think it will be good to put it in the layout, because of the caching.

Kfir

---

<div class="post-metadata">

**Author:** ![Kfir\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e47c2d/32.png) [@Kfir\_L](https://www.ruby-forum.com/u/Kfir_L)\
**Post date:** [June 11, 2006, 4:25pm UTC](https://www.ruby-forum.com/t/javascript-include-in-html-load-times/95733/3 "2006-06-11T16:25:46Z")

</div>

Kfir L. wrote:

> Hi,  
> If I include a javascript library, will it load when the html load, or  
> just at the first use?  
> I have table.js and I have few pages that needs it.  
> Should I include it just on the pages that needs it, or put it on the  
> application\_layout?
> 
> Thanks,  
> Kfir

Most browsers will cache a script file if its not changing, which will  
be your case.

As to whether or not to put the include in every page, well, that  
depends on how many of your pages actually make use of it. If its a  
signficant amount of pages, then go ahead and do it. If only a few pages  
use the JS, then include it directly in the .rhtml.
