Lille
2010-Jul-12 17:42 UTC
newbie: what is preferred approach for including javascript files?
Hi, What is the cost of not cacheing javascript? If that cost is serious, do I prefer to selectively include javascript files only for view where they are needed? In other words I see four options: 1) Cache everything in layouts/application.html.erb and don''t worry about selective inclusion of .js files where they are needed; 2) cache some things in (e.g., dependencies like jquery) and selectively include the rest only where they are needed; 3) do not cache and only include javascript in the views it is needed; 4) cache nothing and include everything in layouts/ application.html.erb. I cobbled together javascript functionality in development mode, such that my layouts/application.html.erb file came to look like this: <html> <head> ... <%= javascript_include_tag :defaults, "jquery-1.4.2.js", :cache=>true %> <!-- using prototype & jquery --> <%= javascript_include_tag "jquery.maskedinput-1.2.2.js", :cache=>true %> <%= javascript_include_tag "autoNumeric-1.5.1.js", :cache=>true %> <%= javascript_include_tag "autoLoader-1.5.1.js", :cache=>true%> <%= javascript_include_tag "jquery.metadata.js", :cache=>true %> ... When, recently, I switched into production mode, I saw that the expected javascripts/all.js cache file had been created, but, unfortunately, a lot of my javascript functionality was knocked out. When I remove the :cache option from my layouts/application.html.erb file, like this... <html> <head> ... <%= javascript_include_tag :defaults, "jquery-1.4.2.js" %> <!-- using prototype & jquery --> <%= javascript_include_tag "jquery.maskedinput-1.2.2.js"%> <%= javascript_include_tag "autoNumeric-1.5.1.js" %> ... ...I get back a lot of my functionality. Thanks, Lille -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Pale Horse
2010-Jul-13 10:25 UTC
Re: newbie: what is preferred approach for including javascript files?
Lille wrote:> > Hi, > > What is the cost of not cacheing javascript?Slower retrieval of the included files.> If that cost is serious, > do I prefer to selectively include javascript files only for view > where they are needed? In other words I see four options:http://guides.rubyonrails.org/layouts_and_rendering.html#asset-tags. See 3.1.2 - Linking to Javascript files.> 1) Cache everything in layouts/application.html.erb and don''t worry > about selective inclusion of .js files where they are needed; > 2) cache some things in (e.g., dependencies like jquery) and > selectively include the rest only where they are needed; > 3) do not cache and only include javascript in the views it is needed; > 4) cache nothing and include everything in layouts/ > application.html.erb.-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.