Rails includes a third-party Javascript library file

I have a Javascript library to load an AJAX file that I need to include on only one page. Where is the best folder for this file? app/assets/javascripts ? vendor/assets/javascripts ? lib/assets/javascripts ? And then I need to enable it on only one page. Or should I just add it to application.js and include it on every page (do I even know that I only use it on one page?)

I was counting on performance. Would it be best to put the mini JS file somewhere and just include it with javascript_include_tag on the page I need, using yield(:head) and content_for(:head) ? Thanks.

+8
javascript ruby-on-rails assets
source share
2 answers

Third-party Java scripts should go into the vendor/assets/javascripts directory, because app/assets/javscripts is for your specific JavaScripts applications, and lib/assets/javascripts is for your library code, which is separate for your application or libraries that you used in different applications.

See Asset Organization for more details.

Regarding the inclusion of javascripts in your application / page, if you use it only on a specific page, then including a file with javascript_include_tag is an approach that I would take as well.

+14
source share

In the vendor/assets/javascripts folder, because this is a folder for a third-party script

0
source share

All Articles