From b67a3a85dd8afabeed3ccdb6ccbfbbc1fbac2a81 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 23 Dec 2013 10:32:07 +1100 Subject: [PATCH] split js with vendor/application avoid one huge js bundle and instead break it down to application and vendor (3rd party) our app changes a lot, vendor changes a lot less --- app/assets/javascripts/application.js.erb | 30 -------------- app/assets/javascripts/ember_include.js.erb | 7 ++++ app/assets/javascripts/jquery_include.js.erb | 7 ++++ app/assets/javascripts/main_include.js | 36 ----------------- app/assets/javascripts/vendor.js | 41 ++++++++++++++++++++ app/views/layouts/application.html.erb | 2 +- config/application.rb | 2 +- 7 files changed, 57 insertions(+), 68 deletions(-) create mode 100644 app/assets/javascripts/ember_include.js.erb create mode 100644 app/assets/javascripts/jquery_include.js.erb create mode 100644 app/assets/javascripts/vendor.js diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index 136c074954e..87d466f8f58 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -1,34 +1,4 @@ -// This is a manifest file that'll be compiled into including all the files listed below. -// Add new JavaScript code in separate files in this directory and they'll automatically -// be included in the compiled file accessible from http://example.com/assets/application.js -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. -// -//= require ./env - -// probe framework first -//= require ./discourse/lib/probes.js - -// Externals we need to load first - <% -if Rails.env.development? - require_asset ("development/jquery-2.0.3.js") -else - require_asset ("production/jquery-2.0.3.min.js") -end - -require_asset("message-bus") - -require_asset ("jquery.ui.widget.js") -require_asset ("handlebars.js") - -if Rails.env.development? - require_asset ("development/ember.js") -else - require_asset ("production/ember.js") -end - require_asset ("./main_include.js") # Include plugin javascripts diff --git a/app/assets/javascripts/ember_include.js.erb b/app/assets/javascripts/ember_include.js.erb new file mode 100644 index 00000000000..3075f05a4ab --- /dev/null +++ b/app/assets/javascripts/ember_include.js.erb @@ -0,0 +1,7 @@ +<% +if Rails.env.development? + require_asset ("development/ember.js") +else + require_asset ("production/ember.js") +end +%> diff --git a/app/assets/javascripts/jquery_include.js.erb b/app/assets/javascripts/jquery_include.js.erb new file mode 100644 index 00000000000..20bde9f0ea7 --- /dev/null +++ b/app/assets/javascripts/jquery_include.js.erb @@ -0,0 +1,7 @@ +<% +if Rails.env.development? + require_asset ("development/jquery-2.0.3.js") +else + require_asset ("production/jquery-2.0.3.min.js") +end +%> diff --git a/app/assets/javascripts/main_include.js b/app/assets/javascripts/main_include.js index e933c64c50e..b1b26036fcd 100644 --- a/app/assets/javascripts/main_include.js +++ b/app/assets/javascripts/main_include.js @@ -1,39 +1,3 @@ -//= require_tree ./discourse/ember - -// The Vendored JS -//= require LAB.js -//= require Markdown.Converter.js -//= require Markdown.Editor.js -//= require better_markdown.js -//= require bootbox.js -//= require bootstrap-alert.js -//= require bootstrap-button.js -//= require bootstrap-dropdown.js -//= require bootstrap-modal.js -//= require bootstrap-transition.js -//= require chosen.jquery.js -//= require ember-renderspeed.js -//= require favcount.js -//= require handlebars.js -//= require jquery.ba-replacetext.js -//= require jquery.ba-resize.min.js -//= require jquery.color.js -//= require jquery.cookie.js -//= require jquery.fileupload.js -//= require jquery.iframe-transport.js -//= require jquery.putcursoratend.js -//= require jquery.tagsinput.js -//= require jquery.ui.widget.js -//= require jquery.sortable.js -//= require lodash.js -//= require md5.js -//= require modernizr.custom.00874.js -//= require mousetrap.js -//= require rsvp.js -//= require show-html.js -//= require lock-on.js -//= require ember-cloaking - //= require ./discourse/helpers/i18n_helpers //= require ./discourse/mixins/ajax //= require ./discourse diff --git a/app/assets/javascripts/vendor.js b/app/assets/javascripts/vendor.js new file mode 100644 index 00000000000..47bbb59072f --- /dev/null +++ b/app/assets/javascripts/vendor.js @@ -0,0 +1,41 @@ +//= require ./env +//= require ./discourse/lib/probes.js + +//= require handlebars.js +//= require jquery_include.js +//= require ember_include.js + +//= require message-bus +//= require jquery.ui.widget.js +//= require_tree ./discourse/ember +//= require LAB.js +//= require Markdown.Converter.js +//= require Markdown.Editor.js +//= require better_markdown.js +//= require bootbox.js +//= require bootstrap-alert.js +//= require bootstrap-button.js +//= require bootstrap-dropdown.js +//= require bootstrap-modal.js +//= require bootstrap-transition.js +//= require chosen.jquery.js +//= require ember-renderspeed.js +//= require favcount.js +//= require jquery.ba-replacetext.js +//= require jquery.ba-resize.min.js +//= require jquery.color.js +//= require jquery.cookie.js +//= require jquery.fileupload.js +//= require jquery.iframe-transport.js +//= require jquery.putcursoratend.js +//= require jquery.tagsinput.js +//= require jquery.ui.widget.js +//= require jquery.sortable.js +//= require lodash.js +//= require md5.js +//= require modernizr.custom.00874.js +//= require mousetrap.js +//= require rsvp.js +//= require show-html.js +//= require lock-on.js +//= require ember-cloaking diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0b3a0f7f798..6568a400cdc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,8 +13,8 @@ <%= javascript_include_tag "preload_store" %> - <%= javascript_include_tag "locales/#{I18n.locale}" %> + <%= javascript_include_tag "vendor" %> <%= javascript_include_tag "application" %> <%- if staff? %> <%= javascript_include_tag "admin"%> diff --git a/config/application.rb b/config/application.rb index 5113500cb17..08375e4e2fc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -58,7 +58,7 @@ module Discourse path =~ /assets\/images/ && !%w(.js .css).include?(File.extname(filename)) end] - config.assets.precompile += ['common.css', 'desktop.css', 'mobile.css', 'admin.js', 'admin.css', 'shiny/shiny.css', 'preload_store.js', 'browser-update.js'] + config.assets.precompile += ['vendor.js', 'common.css', 'desktop.css', 'mobile.css', 'admin.js', 'admin.css', 'shiny/shiny.css', 'preload_store.js', 'browser-update.js'] # Precompile all defer Dir.glob("#{config.root}/app/assets/javascripts/defer/*.js").each do |file|