Brian,  

I think require_tree often leads to problems (it’s one of the first things I 
remove when I’m building an app), but by loading specific JS files per page, 
aren’t you denying your users’ browsers the opportunity to cache the JS from 
other page visits? Separate per-page JavaScript files means your user has to 
download new script assets each time they visit a page related to a controller 
they haven’t visited before.

-Geoff  


On Friday, October 31, 2014 at 13:07, Brian Underwood wrote:

> I posted an issue about this ( 
> https://github.com/rails/rails/issues/17457#issuecomment-61292491 ) but I'll 
> copy/paste here for discussion convenience:
>  
>  
>  
> I feel like I'm the boy telling the emperor he has no clothes, but here 
> goes...
>  
>  
> Every large rails project that I've worked on has had it's application 
> javascript grow and grow because everybody leaves 'require_tree .' in 
> application.js. Personally I hate it and remove it whenever I can (it's 
> harder on legacy projects), but we should be loading javascript in a saner, 
> more modular way.
>  
>  
> Very often I automagically include javascript files for controllers and 
> actions if they exist. Here's an example of a helper that I've recently 
> written (it's not neccessarily pretty, but you get the idea:
>  
> def action_and_controller_javascript_include_tag capture do concat 
> javascript_include_tag controller_name if 
> Rails.root.join("app/assets/javascripts/#{controller_name}.coffee").exist? 
> concat javascript_include_tag "#{controller_name}/#{action_name}" if 
> Rails.root.join("app/assets/javascripts/#{controller_name}/#{action_name}.coffee").exist?
>  end end
>  
>  
> I'd be fine if that were a gem, though rails already generates controller js 
> files so it might make sense still.
>  
>  
> But seriously, can we please encourage not loading all of the javascript for 
> the entire application?
>  
>  
>  
>  
> --  
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to rubyonrails-core+unsubscr...@googlegroups.com 
> (mailto:rubyonrails-core+unsubscr...@googlegroups.com).
> To post to this group, send email to rubyonrails-core@googlegroups.com 
> (mailto:rubyonrails-core@googlegroups.com).
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to