From 7754ea1c7cab26b5b40e7653f1d6cbe7d246c975 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 20 Dec 2017 13:50:12 -0500 Subject: Bug 1361890 - Remove asset concatenation --- Bugzilla/Constants.pm | 7 -- Bugzilla/Install/Filesystem.pm | 22 ------- Bugzilla/Template.pm | 145 +++-------------------------------------- 3 files changed, 9 insertions(+), 165 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index 37917d305..695f2fede 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -26,8 +26,6 @@ use Memoize; bz_locations - CONCATENATE_ASSETS - IS_NULL NOT_NULL @@ -219,11 +217,6 @@ use constant REST_DOC => "https://bugzilla.readthedocs.io/en/latest/api/"; use constant REMOTE_FILE => 'http://updates.bugzilla.org/bugzilla-update.xml'; use constant LOCAL_FILE => 'bugzilla-update.xml'; # Relative to datadir. -# When true CSS and JavaScript assets will be concatanted and minified at -# run-time, to reduce the number of requests required to render a page. -# Setting this to a false value can help debugging. -use constant CONCATENATE_ASSETS => 1; - # These are unique values that are unlikely to match a string or a number, # to be used in criteria for match() functions and other things. They start # and end with spaces because most Bugzilla stuff has trim() called on it, diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 01b8d7e8e..89a1e5d93 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -579,7 +579,6 @@ sub update_filesystem { _remove_empty_css_files(); _convert_single_file_skins(); - _remove_dynamic_assets(); } sub _css_url_fix { @@ -645,27 +644,6 @@ sub _convert_single_file_skins { } } -# delete all automatically generated css/js files to force recreation at the -# next request. -sub _remove_dynamic_assets { - my @files = ( - glob(bz_locations()->{assetsdir} . '/*.css'), - glob(bz_locations()->{assetsdir} . '/*.js'), - ); - foreach my $file (@files) { - unlink($file); - } - - # remove old skins/assets directory - my $old_path = bz_locations()->{skinsdir} . '/assets'; - if (-d $old_path) { - foreach my $file (glob("$old_path/*.css")) { - unlink($file); - } - rmdir($old_path); - } -} - sub create_htaccess { _create_files(%{FILESYSTEM()->{htaccess}}); diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index c91b6470c..a027614ec 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -364,22 +364,9 @@ sub multiline_sprintf { # Header Generation # ##################### -# Returns the last modification time of a file, as an integer number of -# seconds since the epoch. -sub _mtime { return (stat($_[0]))[9] } - -sub mtime_filter { - my ($file_url, $mtime) = @_; - # This environment var is set in the .htaccess if we have mod_headers - # and mod_expires installed, to make sure that JS and CSS with "?" - # after them will still be cached by clients. - return $file_url if !$ENV{BZ_CACHE_CONTROL}; - if (!$mtime) { - my $cgi_path = bz_locations()->{'cgi_path'}; - my $file_path = "$cgi_path/$file_url"; - $mtime = _mtime($file_path); - } - return "$file_url?$mtime"; +sub version_filter { + my ($file_url) = @_; + return "static/v" . Bugzilla->VERSION . "/$file_url"; } # Set up the skin CSS cascade: @@ -408,18 +395,13 @@ sub css_files { } } - # build unified - $by_type{unified_standard_skin} = _concatenate_css($by_type{standard}, - $by_type{skin}); - $by_type{unified_custom} = _concatenate_css($by_type{custom}); - return \%by_type; } sub _css_link_set { my ($file_name) = @_; - my %set = (standard => mtime_filter($file_name)); + my %set = (standard => version_filter($file_name)); # We use (?:^|/) to allow Extensions to use the skins system if they want. if ($file_name !~ m{(?:^|/)skins/standard/}) { @@ -430,127 +412,19 @@ sub _css_link_set { my $cgi_path = bz_locations()->{'cgi_path'}; my $skin_file_name = $file_name; $skin_file_name =~ s{(?:^|/)skins/standard/}{skins/contrib/$skin/}; - if (my $mtime = _mtime("$cgi_path/$skin_file_name")) { - $set{skin} = mtime_filter($skin_file_name, $mtime); + if (-f "$cgi_path/$skin_file_name") { + $set{skin} = version_filter($skin_file_name); } my $custom_file_name = $file_name; $custom_file_name =~ s{(?:^|/)skins/standard/}{skins/custom/}; - if (my $custom_mtime = _mtime("$cgi_path/$custom_file_name")) { - $set{custom} = mtime_filter($custom_file_name, $custom_mtime); + if (-f "$cgi_path/$custom_file_name") { + $set{custom} = version_filter($custom_file_name); } return \%set; } -sub _concatenate_css { - my @sources = map { @$_ } @_; - return unless @sources; - - my %files = - map { - (my $file = $_) =~ s/(^[^\?]+)\?.+/$1/; - $_ => $file; - } @sources; - - my $cgi_path = bz_locations()->{cgi_path}; - my $skins_path = bz_locations()->{assetsdir}; - - # build minified files - my @minified; - foreach my $source (@sources) { - next unless -e "$cgi_path/$files{$source}"; - my $file = $skins_path . '/' . md5_hex($source) . '.css'; - if (!-e $file) { - my $content = read_file("$cgi_path/$files{$source}"); - - # minify - $content =~ s{/\*.*?\*/}{}sg; # comments - $content =~ s{(^\s+|\s+$)}{}mg; # leading/trailing whitespace - $content =~ s{\n}{}g; # single line - - # rewrite urls - $content =~ s{url\(([^\)]+)\)}{_css_url_rewrite($source, $1)}eig; - - write_file($file, "/* $files{$source} */\n" . $content . "\n"); - } - push @minified, $file; - } - - # concat files - my $file = $skins_path . '/' . md5_hex(join(' ', @sources)) . '.css'; - if (!-e $file) { - my $content = ''; - foreach my $source (@minified) { - $content .= read_file($source); - } - write_file($file, $content); - } - - $file =~ s/^\Q$cgi_path\E\///o; - return mtime_filter($file); -} - -sub _css_url_rewrite { - my ($source, $url) = @_; - # rewrite relative urls as the unified stylesheet lives in a different - # directory from the source - $url =~ s/(^['"]|['"]$)//g; - if (substr($url, 0, 1) eq '/' || substr($url, 0, 5) eq 'data:') { - return 'url(' . $url . ')'; - } - return 'url(../../' . dirname($source) . '/' . $url . ')'; -} - -sub _concatenate_js { - return @_ unless CONCATENATE_ASSETS; - my ($sources) = @_; - return [] unless $sources; - $sources = ref($sources) ? $sources : [ $sources ]; - - my %files = - map { - (my $file = $_) =~ s/(^[^\?]+)\?.+/$1/; - $_ => $file; - } @$sources; - - my $cgi_path = bz_locations()->{cgi_path}; - my $skins_path = bz_locations()->{assetsdir}; - - # build minified files - my @minified; - foreach my $source (@$sources) { - next unless -e "$cgi_path/$files{$source}"; - my $file = $skins_path . '/' . md5_hex($source) . '.js'; - if (!-e $file) { - my $content = read_file("$cgi_path/$files{$source}"); - - # minimal minification - $content =~ s#/\*.*?\*/##sg; # block comments - $content =~ s#(^ +| +$)##gm; # leading/trailing spaces - $content =~ s#^//.+$##gm; # single line comments - $content =~ s#\n{2,}#\n#g; # blank lines - $content =~ s#(^\s+|\s+$)##g; # whitespace at the start/end of file - - write_file($file, "/* $files{$source} */\n" . $content . "\n"); - } - push @minified, $file; - } - - # concat files - my $file = $skins_path . '/' . md5_hex(join(' ', @$sources)) . '.js'; - if (!-e $file) { - my $content = ''; - foreach my $source (@minified) { - $content .= read_file($source); - } - write_file($file, $content); - } - - $file =~ s/^\Q$cgi_path\E\///o; - return [ $file ]; -} - # YUI dependency resolution sub yui_resolve_deps { my ($yui, $yui_deps) = @_; @@ -899,7 +773,7 @@ sub create { email => \&Bugzilla::Util::email_filter, - mtime => \&mtime_filter, + version => \&version_filter, # iCalendar contentline filter ics => [ sub { @@ -1089,7 +963,6 @@ sub create { 'css_files' => \&css_files, yui_resolve_deps => \&yui_resolve_deps, - concatenate_js => \&_concatenate_js, # Whether or not keywords are enabled, in this Bugzilla. 'use_keywords' => sub { return Bugzilla::Keyword->any_exist; }, -- cgit v1.2.3-24-g4f1b