admin管理员组

文章数量:1384246

When creating a new Rails application, it is automatically supplied with several quite large js files. In the application layout, by default, all of them are loaded into the page:

<%= javascript_include_tag :defaults %>

I was wondering, isn't loading all those javascripts can make the site possibly mush slower?
And if so, where can I change the definition of :defaults? Or should I just include the ones I need and remove the code line mentioned above?

Thank you

When creating a new Rails application, it is automatically supplied with several quite large js files. In the application layout, by default, all of them are loaded into the page:

<%= javascript_include_tag :defaults %>

I was wondering, isn't loading all those javascripts can make the site possibly mush slower?
And if so, where can I change the definition of :defaults? Or should I just include the ones I need and remove the code line mentioned above?

Thank you

Share Improve this question asked Jan 16, 2011 at 13:51 hizkihizki 7191 gold badge8 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

In config/application.rb

# JavaScript files you want as :defaults (application.js is always included).
config.action_view.javascript_expansions[:defaults] = %w(jquery.js rails.js)

Using :defaults is not mandatory in any way. If you are worried about performance you should read at least the caching part from javascript_include_tag docs:

  • http://apidock./rails/ActionView/Helpers/AssetTagHelper/javascript_include_tag

本文标签: javascriptDefault js included in RailsStack Overflow