# Good practice to include javascript functions in view?

**URL:** <https://www.ruby-forum.com/t/good-practice-to-include-javascript-functions-in-view/87300>\
**Category:** Rails\
**Created:** [March 1, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/good-practice-to-include-javascript-functions-in-view/87300 "2007-03-01T15:39:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [March 1, 2007, 3:39pm UTC](https://www.ruby-forum.com/t/good-practice-to-include-javascript-functions-in-view/87300/1 "2007-03-01T15:39:22Z")

</div>

Hello,

I was just wondering if it was good pratice to have a load of javascript  
functions in a view file, or whether these javascript functions should  
be put in a javascript file and loaded in.

Thanks for your time.

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [March 1, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/good-practice-to-include-javascript-functions-in-view/87300/2 "2007-03-01T20:28:06Z")

</div>

On Thu, Mar 01, 2007 at 03:39:22PM +0100, James S. wrote:

> I was just wondering if it was good pratice to have a load of javascript  
> functions in a view file, or whether these javascript functions should  
> be put in a javascript file and loaded in.

Static assets should be served as static assets. It makes sense to have  
a  
script tag (e.g. javascript\_tag) in your views, and maybe an occasional  
and  
very small script tag with inline code that uses functions/objects in  
your  
static JS files. If you find yourself writing more than three or so  
lines  
of JS in a view, you should probably pull it out into a static JS file.

> Thanks for your time.  
> –Greg
