[英]Rails Include Third Party Javascript Library File
I've got a Javascript library for AJAX file uploading that I need to include on only one page. 我有一个用于AJAX文件上传的Javascript库,我只需要在一个页面上包含它。 Where is the best folder for this for file?
这个文件的最佳文件夹在哪里?
app/assets/javascripts
? app/assets/javascripts
? vendor/assets/javascripts
? vendor/assets/javascripts
? lib/assets/javascripts
? lib/assets/javascripts
? And then I need to be able to include it on only one page. 然后我需要能够将它包含在一个页面上。 Or should I just add it to
application.js
and have it included on every page (even know I'm only using it on one page?) 或者我应该将它添加到
application.js
并将其包含在每个页面上(甚至知道我只在一个页面上使用它?)
I figured for performance my best bet would be to put the minified JS file somewhere, and just include it with a javascript_include_tag
on the page I need it, by using yield(:head)
and content_for(:head)
? 我认为性能最好的方法是将缩小的JS文件放在某个地方,然后在我需要的页面上用
javascript_include_tag
包含它,使用yield(:head)
和content_for(:head)
? Thank you. 谢谢。
Third party JavaScripts should go inside vendor/assets/javascripts
directory, because app/assets/javscripts
is for your application specific JavaScripts and lib/assets/javascripts
is for your libraries code which is separate to your application or libraries that you have shared across different applications. 第三方JavaScripts应该位于
vendor/assets/javascripts
目录中,因为app/assets/javscripts
是针对特定于应用程序的JavaScripts而lib/assets/javascripts
是针对您的库代码的,这些代码与您在不同的应用程序或库之间共享应用。
Please reference Asset Organization for further details. 请参阅资产组织了解更多详情。
As far as inclusion of javascripts in your application/page if you're using it only on a specific page then including the file with javascript_include_tag
is the approach I would take as well. 至于在您的应用程序/页面中包含javascripts,如果您仅在特定页面上使用它,那么我将采用
javascript_include_tag
包含该文件。
在文件夹vendor/assets/javascripts
因为是第三方脚本的文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.