Commit cc5ea574d003040c95e51bbc2b9ff057f8bc2a60

Authored by Antonio Terceiro
1 parent 50da5683

Minimize number of HTTP requests for plugin assets

(ActionItem2314)
Showing 1 changed file with 8 additions and 10 deletions   Show diff stats
app/views/layouts/application-ng.rhtml
@@ -12,21 +12,19 @@ @@ -12,21 +12,19 @@
12 <%= stylesheet_link_tag template_stylesheet_path %> 12 <%= stylesheet_link_tag template_stylesheet_path %>
13 <%= stylesheet_link_tag icon_theme_stylesheet_path %> 13 <%= stylesheet_link_tag icon_theme_stylesheet_path %>
14 <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %> 14 <%= stylesheet_link_tag jquery_ui_theme_stylesheet_path %>
15 - <% @plugins.enabled_plugins.each do |plugin| %>  
16 - <% if plugin.stylesheet? %>  
17 - <%= stylesheet_tag plugin.class.public_path('style.css'), {} %>  
18 - <% end %>  
19 - <% end %> 15 + <%
  16 + plugins_stylesheets = @plugins.enabled_plugins.select(&:stylesheet?).map { |plugin| plugin.class.public_path('style.css') }
  17 + %>
  18 + <%= stylesheet_link_tag(plugins_stylesheets, :cache => 'cache-plugins-style-' + Digest::MD5.hexdigest(plugins_stylesheets.to_s)) unless plugins_stylesheets.empty? %>
20 <%= stylesheet_link_tag theme_stylesheet_path %> 19 <%= stylesheet_link_tag theme_stylesheet_path %>
21 20
22 <%# Add custom tags/styles/etc via content_for %> 21 <%# Add custom tags/styles/etc via content_for %>
23 <%= yield :head %> 22 <%= yield :head %>
24 <%= javascript_tag('render_all_jquery_ui_widgets()') %> 23 <%= javascript_tag('render_all_jquery_ui_widgets()') %>
25 - <% @plugins.enabled_plugins.each do |plugin| %>  
26 - <% plugin.js_files.each do |js_file| %>  
27 - <%= javascript_src_tag plugin.class.public_path(js_file), {} %>  
28 - <% end %>  
29 - <% end %> 24 + <%
  25 + plugins_javascripts = @plugins.enabled_plugins.map { |plugin| plugin.js_files.map { |js| plugin.class.public_path(js) } }.flatten
  26 + %>
  27 + <%= javascript_include_tag(plugins_javascripts, :cache => 'cache-plugins-js-' + Digest::MD5.hexdigest(plugins_javascripts.to_s)) unless plugins_javascripts.empty? %>
30 <%= 28 <%=
31 @plugins.map(:head_ending).collect do |content| 29 @plugins.map(:head_ending).collect do |content|
32 content.respond_to?(:call) ? content.call : content 30 content.respond_to?(:call) ? content.call : content