A platform for community discussion. Free, open, simple.
PERF: Stop precompressing assets with gzip (#43949)
David Taylor9e41a3e35c67
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex dd6c362fac1..251109ace1c 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -95,10 +95,6 @@ module ApplicationHelperrequest.env["HTTP_ACCEPT_ENCODING"] =~ /br/end- def is_gzip_req?- request.env["HTTP_ACCEPT_ENCODING"] =~ /gzip/- end-def generate_import_map(plugin_assets)imports =plugin_assets@@ -150,11 +146,7 @@ module ApplicationHelperpath = "#{resolved_s3_asset_cdn_url}#{path}"end- if is_brotli_req?- path = path.sub("/assets/js/", "/assets/br/")- elsif is_gzip_req?- path = path.sub("/assets/js/", "/assets/gz/")- end+ path = path.sub("/assets/js/", "/assets/br/") if is_brotli_req?endpathdiff --git a/config/nginx.sample.conf b/config/nginx.sample.confindex b18c43ac177..bfe40e8dbc9 100644--- a/config/nginx.sample.conf+++ b/config/nginx.sample.conf@@ -142,7 +142,6 @@ server {expires 1y;# asset pipeline enables thisbrotli_static on;- gzip_static on;add_header Cache-Control public,immutable;add_header Access-Control-Allow-Origin *;# HOOK in asset location (used for extensibility)diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rakeindex 3c9ca03d59d..3cb83c5bb1e 100644--- a/lib/tasks/assets.rake+++ b/lib/tasks/assets.rake@@ -70,11 +70,6 @@ def assets_path"#{Rails.public_path.join("assets")}"end-def gzip(path)- cmd = "gzip -f -c -9 #{path} > #{path}.gz"- system cmd, exception: true-end-def brotli_command(path)compression_quality = ENV["DISCOURSE_ASSETS_PRECOMPILE_DEFAULT_BROTLI_QUALITY"] || "6""brotli -f --quality=#{compression_quality} #{path} --output=#{path}.br"@@ -131,17 +126,12 @@ task "assets:precompile:compress_js": "environment" dofile_path = "public/assets/#{digested_path}"- if File.exist?("#{file_path}.gz") && File.exist?("#{file_path}.br")+ if File.exist?("#{file_path}.br")STDERR.puts "Already compressed: #{digested_path}"nextend- proc.call do- log_task_duration(digested_path) do- gzip(file_path)- brotli(file_path)- end- end+ proc.call { log_task_duration(digested_path) { brotli(file_path) } }endendenddiff --git a/lib/tasks/s3.rake b/lib/tasks/s3.rakeindex 747b34bb553..b21f3ba35f0 100644--- a/lib/tasks/s3.rake+++ b/lib/tasks/s3.rake@@ -7,13 +7,6 @@ def brotli_s3_path(path)"#{path[0..-ext.length]}br#{ext}"end-def gzip_s3_path(path)- return path.sub(%r{^assets/js/}, "assets/gz/").sub(/\.gz$/, "") if path.start_with?("assets/js/")-- ext = File.extname(path)- "#{path[0..-ext.length]}gz#{ext}"-end-def existing_assets@existing_assets ||= Set.new(helper.list("assets/").map(&:key))end@@ -74,10 +67,6 @@ def assetsif File.exist?(fullpath + ".br")results << [fullpath + ".br", brotli_s3_path(asset_path), content_type, "br"]end-- if File.exist?(fullpath + ".gz")- results << [fullpath + ".gz", gzip_s3_path(asset_path), content_type, "gzip"]- endendresults.to_adiff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex 5e150ce7091..0c0ae7c78bc 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -112,12 +112,6 @@ RSpec.describe ApplicationHelper doexpect(link).to include(%r{https://s3cdn.com/assets/js/discourse-\w{8}.digested.js})end- it "can fall back to gzip compression" do- helper.request.env["HTTP_ACCEPT_ENCODING"] = "gzip"- link = helper.preload_script("discourse")- expect(link).to include(%r{https://s3cdn.com/assets/gz/discourse-\w{8}.digested.js})- end-it "gives s3 cdn even if asset host is set" doset_cdn_url "https://awesome.com"link = helper.preload_script("discourse")