Reputation: 4462
When writing partials in Rails I sometimes feel the urge to use inline Javascript for basic DOM manipulation functions that will only ever be relevant to the HTML in the partial. Should I feel bad about this?
My thoughts are that separating out 20 lines of JS into a separate file won't save more than a few KB of bandwidth (in fact it'll probably cost due to the latency of the extra req) and will be hard to organize since I'll have a JS file full of miscellaneous functions separated from their context.
Every one says never use inline JS, but I feel like there's something I'm just not getting here, can someone set me straight?
Upvotes: 1
Views: 578
Reputation: 7586
When necessary, I prefer to generate only inline function calls, perhaps with some server-generated parameters. The function is implemented in a .js file so that I can ensure consistency across the app.
Upvotes: 0
Reputation: 7841
I personally think it's more than just to save the bandwidth, it's also about
I believe there are a whole lot more reasons where you are encouraged to separate the js from the partial
Hope it helps =)
Upvotes: 2