Merge branch 'cs-unnecessary-assets' into 'master'

Load d3 only when necessary

Now d3 is only loaded on the users' show page and the graphs pages, where it's necessary.

Redo of !3993.

This decreases page size from 4.6MB to 4.3MB for a given Activity page (before compression), or a savings of 300KB. This is essentially a proof of concept for removing larger dependencies such as the Ace Editor, Chart.js, and Raphael, which will likely provide another 1MB of savings on most pages (again, before compression).

See merge request !4394
This commit is contained in:
Robert Speicher 2016-06-02 02:49:44 +00:00
commit 30524901e2
16 changed files with 39 additions and 8 deletions

View File

@ -18,7 +18,6 @@
#= require jquery.atwho
#= require jquery.scrollTo
#= require jquery.turbolinks
#= require d3
#= require turbolinks
#= require autosave
#= require bootstrap/affix
@ -51,7 +50,13 @@
#= require shortcuts_network
#= require jquery.nicescroll
#= require date.format
#= require_tree .
#= require_directory ./behaviors
#= require_directory ./blob
#= require_directory ./ci
#= require_directory ./commit
#= require_directory ./extensions
#= require_directory ./lib
#= require_directory .
#= require fuzzaldrin-plus
#= require cropper

View File

@ -0,0 +1,7 @@
# This is a manifest file that'll be compiled into including all the files listed below.
# Add new JavaScript/Coffee 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_tree .

View File

@ -1,5 +1,4 @@
#= require d3
#= require stat_graph_contributors_util
class @ContributorsStatGraph
init: (log) ->

View File

@ -1,6 +1,4 @@
#= require d3
#= require jquery
#= require underscore
class @ContributorsGraph
MARGIN:

View File

@ -0,0 +1,8 @@
# This is a manifest file that'll be compiled into including all the files listed below.
# Add new JavaScript/Coffee 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 d3
#= require_tree .

View File

@ -0,0 +1,7 @@
module JavascriptHelper
def page_specific_javascripts(js = nil)
@page_specific_javascripts = js unless js.nil?
@page_specific_javascripts
end
end

View File

@ -30,6 +30,9 @@
= javascript_include_tag "application"
- if page_specific_javascripts
= javascript_include_tag page_specific_javascripts, {"data-turbolinks-track" => true}
= csrf_meta_tags
= include_gon

View File

@ -1,3 +1,4 @@
- page_specific_javascripts asset_path("graphs/application.js")
%ul.nav-links
= nav_link(action: :show) do
= link_to 'Contributors', namespace_project_graph_path

View File

@ -1,5 +1,6 @@
- page_title @user.name
- page_description @user.bio
- page_specific_javascripts asset_path("users/application.js")
- header_title @user.name, user_path(@user)
- @no_container = true

View File

@ -81,6 +81,8 @@ module Gitlab
config.assets.precompile << "print.css"
config.assets.precompile << "notify.css"
config.assets.precompile << "mailers/*.css"
config.assets.precompile << "graphs/application.js"
config.assets.precompile << "users/application.js"
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

View File

@ -1,4 +1,4 @@
//= require stat_graph_contributors_graph
//= require graphs/stat_graph_contributors_graph
describe("ContributorsGraph", function () {
describe("#set_x_domain", function () {

View File

@ -1,4 +1,4 @@
//= require stat_graph_contributors_util
//= require graphs/stat_graph_contributors_util
describe("ContributorsStatGraphUtil", function () {

View File

@ -1,4 +1,4 @@
//= require stat_graph
//= require graphs/stat_graph
describe("StatGraph", function () {