From 6947ebcbb78abd0ee55854543df45ac21e3b0343 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 14:32:43 +0100 Subject: [PATCH 01/23] Refactor upload method to make enhancing nicer --- lib/asset_sync/storage.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index f78b202..d049f22 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -55,12 +55,14 @@ def delete_extra_remote_files def upload_file(f) STDERR.puts "Uploading: #{f}" - file = bucket.files.create( - :key => "#{f}", + file = { + :key => f, :body => File.open("#{path}/#{f}"), :public => true, :cache_control => "max-age=31557600" - ) + } + + file = bucket.files.create( file ) end def upload_files From 08d49837c3476279b893075371b6b19e8e24cfc9 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 14:41:55 +0100 Subject: [PATCH 02/23] Upload GZIP compressed assets nicely to S3 with correct content type and encoding. --- lib/asset_sync/storage.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index d049f22..5b4fa39 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -62,6 +62,18 @@ def upload_file(f) :cache_control => "max-age=31557600" } + ext = File.extname(f) + gzip = ext == ".gz" + + if gzip + real_ext = File.extname( f.gsub(/\.gz$/,'') )[1..-1] + mime = Mime::Type.lookup_by_extension( real_ext ) + file.merge!({ + :content_type => mime, + :content_encoding => 'gzip' + }) + end + file = bucket.files.create( file ) end From f66e0f046b54eb37ba48cb8cfca10a248ec1104f Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 14:59:22 +0100 Subject: [PATCH 03/23] Overwrite original files with gzipped equivalent, improve logging to show GZIP in action, make it a configurable option, config.gzip_compression that defaults to false --- lib/asset_sync/config.rb | 7 +++++++ lib/asset_sync/storage.rb | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index 6162fdf..8735f68 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -9,6 +9,7 @@ class Invalid < StandardError; end attr_accessor :aws_bucket attr_accessor :aws_region attr_accessor :existing_remote_files + attr_accessor :gzip_compression validates :aws_access_key, :presence => true validates :aws_access_secret, :presence => true @@ -19,9 +20,14 @@ def initialize self.provider = 'AWS' self.aws_region = nil self.existing_remote_files = 'keep' + self.gzip_compression = false load_yml! if yml_exists? end + def gzip? + self.gzip_compression + end + def existing_remote_files? (self.existing_remote_files == "keep") end @@ -45,6 +51,7 @@ def load_yml! self.aws_bucket = yml["aws_bucket"] if yml.has_key?("aws_bucket") self.aws_region = yml["aws_region"] if yml.has_key?("aws_region") self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files") + self.gzip_compression = yml["gzip_compression"] if yml.has_key?("gzip_compression") # TODO deprecate old style config settings self.aws_access_key = yml["access_key_id"] if yml.has_key?("access_key_id") diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 5b4fa39..2c911f3 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -54,7 +54,6 @@ def delete_extra_remote_files end def upload_file(f) - STDERR.puts "Uploading: #{f}" file = { :key => f, :body => File.open("#{path}/#{f}"), @@ -66,12 +65,17 @@ def upload_file(f) gzip = ext == ".gz" if gzip - real_ext = File.extname( f.gsub(/\.gz$/,'') )[1..-1] - mime = Mime::Type.lookup_by_extension( real_ext ) + original = f.gsub(/\.gz$/,'') + original_ext = File.extname( original )[1..-1] + mime = Mime::Type.lookup_by_extension( original_ext ) file.merge!({ + :key => original, :content_type => mime, :content_encoding => 'gzip' }) + STDERR.puts "Uploading: #{f} in place of #{original}" + else + STDERR.puts "Uploading: #{f}" end file = bucket.files.create( file ) From 01149b9d17be9d77e2af940ca03febe316c5f7c3 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 15:00:27 +0100 Subject: [PATCH 04/23] Only handle gzip files specially if we have configured gzip_compression --- lib/asset_sync/storage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 2c911f3..13386f6 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -64,7 +64,7 @@ def upload_file(f) ext = File.extname(f) gzip = ext == ".gz" - if gzip + if gzip && config.gzip? original = f.gsub(/\.gz$/,'') original_ext = File.extname( original )[1..-1] mime = Mime::Type.lookup_by_extension( original_ext ) From 17749930fb503d485be977d67f2c9769edfdfefd Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 15:08:12 +0100 Subject: [PATCH 05/23] Bump version (no release just yet) --- lib/asset_sync/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_sync/version.rb b/lib/asset_sync/version.rb index b713a98..917fbbb 100644 --- a/lib/asset_sync/version.rb +++ b/lib/asset_sync/version.rb @@ -1,3 +1,3 @@ module AssetSync - VERSION = "0.1.8" + VERSION = "0.1.9" end From 0b058d19ebe5c9417c99e6f5000054c99b04c865 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 15:16:56 +0100 Subject: [PATCH 06/23] Instead of overwriting the original file when processing the .gz, overwrite the original if a gz file exists to avoid any issues with whichever order files are processed in --- lib/asset_sync/storage.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 13386f6..116c6cc 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -61,19 +61,18 @@ def upload_file(f) :cache_control => "max-age=31557600" } - ext = File.extname(f) - gzip = ext == ".gz" + gzipped = "#{f}.gz" - if gzip && config.gzip? - original = f.gsub(/\.gz$/,'') - original_ext = File.extname( original )[1..-1] - mime = Mime::Type.lookup_by_extension( original_ext ) + if File.exists?(gzipped) && config.gzip? + ext = File.extname( f )[1..-1] + mime = Mime::Type.lookup_by_extension( ext ) file.merge!({ - :key => original, + :key => f, + :body => File.open("#{path}/#{gzipped}"), :content_type => mime, :content_encoding => 'gzip' }) - STDERR.puts "Uploading: #{f} in place of #{original}" + STDERR.puts "Uploading: #{gzipped} in place of #{f}" else STDERR.puts "Uploading: #{f}" end From a0b3f3e64aa2e3baab51abc9a442839cac2180d4 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 15:20:13 +0100 Subject: [PATCH 07/23] Add path --- lib/asset_sync/storage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 116c6cc..23047a4 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -61,7 +61,7 @@ def upload_file(f) :cache_control => "max-age=31557600" } - gzipped = "#{f}.gz" + gzipped = "#{path}/#{f}.gz" if File.exists?(gzipped) && config.gzip? ext = File.extname( f )[1..-1] From 77301345f01f2df3499e44dc58b2c3562cac1cee Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 15:23:28 +0100 Subject: [PATCH 08/23] Refactor to computed path --- lib/asset_sync/storage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 23047a4..bf633ad 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -68,7 +68,7 @@ def upload_file(f) mime = Mime::Type.lookup_by_extension( ext ) file.merge!({ :key => f, - :body => File.open("#{path}/#{gzipped}"), + :body => File.open(gzipped), :content_type => mime, :content_encoding => 'gzip' }) From 2b051e618532c2ade9c0bf1cab01439e8a568bf7 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 15:56:21 +0100 Subject: [PATCH 09/23] Add todo --- lib/asset_sync/storage.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index bf633ad..93913a5 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -61,6 +61,7 @@ def upload_file(f) :cache_control => "max-age=31557600" } + # TODO don't bother uploading gzipped assets if we're doing this gzipped = "#{path}/#{f}.gz" if File.exists?(gzipped) && config.gzip? From 76618419867417b48e05aa5531f1b8c2890f5e72 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 16:27:31 +0100 Subject: [PATCH 10/23] Set http header Vary: Accept-Encoding when storing gzipped assets to S3 --- lib/asset_sync/storage.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 93913a5..88c7132 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -71,7 +71,10 @@ def upload_file(f) :key => f, :body => File.open(gzipped), :content_type => mime, - :content_encoding => 'gzip' + :content_encoding => 'gzip', + :headers => { + "Vary" => "Accept-Encoding" + } }) STDERR.puts "Uploading: #{gzipped} in place of #{f}" else From f795b90ea357400f603ebf037ea0b4199c55e672 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 16:50:45 +0100 Subject: [PATCH 11/23] Try setting vary header a different way --- lib/asset_sync/storage.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 88c7132..b4fe7f3 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -72,9 +72,7 @@ def upload_file(f) :body => File.open(gzipped), :content_type => mime, :content_encoding => 'gzip', - :headers => { - "Vary" => "Accept-Encoding" - } + :vary => "Accept-Encoding" }) STDERR.puts "Uploading: #{gzipped} in place of #{f}" else From c1267ce125eef3df44c0c9d9110ffbb90d140f87 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 17:17:17 +0100 Subject: [PATCH 12/23] Do not set a Vary: Accept-Encoding header, S3 does not support at all --- lib/asset_sync/storage.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index b4fe7f3..93913a5 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -71,8 +71,7 @@ def upload_file(f) :key => f, :body => File.open(gzipped), :content_type => mime, - :content_encoding => 'gzip', - :vary => "Accept-Encoding" + :content_encoding => 'gzip' }) STDERR.puts "Uploading: #{gzipped} in place of #{f}" else From 49148532a9861018f778bd9453d435f2ce14a950 Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 17:27:56 +0100 Subject: [PATCH 13/23] Ignore .gz assets if we are in gzip_compression mode --- lib/asset_sync/storage.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 93913a5..b141102 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -61,10 +61,13 @@ def upload_file(f) :cache_control => "max-age=31557600" } - # TODO don't bother uploading gzipped assets if we're doing this gzipped = "#{path}/#{f}.gz" - if File.exists?(gzipped) && config.gzip? + if File.extname(f) == ".gz" && config.gzip? + # Don't bother uploading gzipped assets if we are in gzip_compression mode + # as we will overwrite file.css with file.css.gz if it exists. + STDERR.puts "Ignoring: #{f}" + elsif File.exists?(gzipped) && config.gzip? ext = File.extname( f )[1..-1] mime = Mime::Type.lookup_by_extension( ext ) file.merge!({ From 143c35b3425612341867983bae66ed94dfe30c8e Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 17:29:37 +0100 Subject: [PATCH 14/23] Reorder logic to execute quicker if gzip? compression disabled and ignore .gz uploads correctly --- lib/asset_sync/storage.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index b141102..261f5e7 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -62,12 +62,14 @@ def upload_file(f) } gzipped = "#{path}/#{f}.gz" + ignore = false - if File.extname(f) == ".gz" && config.gzip? + if config.gzip? && File.extname(f) == ".gz" # Don't bother uploading gzipped assets if we are in gzip_compression mode # as we will overwrite file.css with file.css.gz if it exists. STDERR.puts "Ignoring: #{f}" - elsif File.exists?(gzipped) && config.gzip? + ignore = true + elsif config.gzip? && File.exists?(gzipped) ext = File.extname( f )[1..-1] mime = Mime::Type.lookup_by_extension( ext ) file.merge!({ @@ -81,7 +83,7 @@ def upload_file(f) STDERR.puts "Uploading: #{f}" end - file = bucket.files.create( file ) + file = bucket.files.create( file ) unless ignore end def upload_files From a1547aef084316180ece92bf610397e9649d78ef Mon Sep 17 00:00:00 2001 From: David Rice Date: Mon, 24 Oct 2011 22:24:20 +0100 Subject: [PATCH 15/23] Add spec for gzip? config method --- spec/asset_sync_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/asset_sync_spec.rb b/spec/asset_sync_spec.rb index 1a81aa1..997a6c8 100644 --- a/spec/asset_sync_spec.rb +++ b/spec/asset_sync_spec.rb @@ -82,4 +82,18 @@ lambda{ AssetSync.sync }.should raise_error(AssetSync::Config::Invalid) end +end + +describe AssetSync, 'with gzip_compression enabled' do + + before(:all) do + Rails.root = 'without_yml' + AssetSync.config = AssetSync::Config.new + AssetSync.config.gzip_compression = true + end + + it "config.gzip? should be true" do + AssetSync.config.gzip?.should be_true + end + end \ No newline at end of file From f28bac02303441c1c9c44f9d69ab451032a5d673 Mon Sep 17 00:00:00 2001 From: David Rice Date: Sat, 5 Nov 2011 21:59:42 +0000 Subject: [PATCH 16/23] Output % savings when uploading gzipped files. Only use gzipped files if the compressed version is actually smaller than the original. --- lib/asset_sync/storage.rb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 261f5e7..f3b1ec9 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -70,15 +70,24 @@ def upload_file(f) STDERR.puts "Ignoring: #{f}" ignore = true elsif config.gzip? && File.exists?(gzipped) - ext = File.extname( f )[1..-1] - mime = Mime::Type.lookup_by_extension( ext ) - file.merge!({ - :key => f, - :body => File.open(gzipped), - :content_type => mime, - :content_encoding => 'gzip' - }) - STDERR.puts "Uploading: #{gzipped} in place of #{f}" + original_size = File.size("#{path}/#{f}") + gzipped_size = File.size(gzipped) + + if gzipped_size < original_size + percentage = ((gzipped_size.to_f/original_size.to_f)*100).round(2) + ext = File.extname( f )[1..-1] + mime = Mime::Type.lookup_by_extension( ext ) + file.merge!({ + :key => f, + :body => File.open(gzipped), + :content_type => mime, + :content_encoding => 'gzip' + }) + STDERR.puts "Uploading: #{gzipped} in place of #{f} saving #{percentage}" + else + percentage = ((original_size.to_f/gzipped_size.to_f)*100).round(2) + STDERR.puts "Uploading: #{f} instead of #{gzipped} (compression increases this file by #{percentage})" + end else STDERR.puts "Uploading: #{f}" end From df5bc04e76e2b7dee3f332867d2b319a276dc38c Mon Sep 17 00:00:00 2001 From: David Rice Date: Sat, 5 Nov 2011 22:15:08 +0000 Subject: [PATCH 17/23] Add % symbol for clarity --- lib/asset_sync/storage.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index f3b1ec9..844c543 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -83,10 +83,10 @@ def upload_file(f) :content_type => mime, :content_encoding => 'gzip' }) - STDERR.puts "Uploading: #{gzipped} in place of #{f} saving #{percentage}" + STDERR.puts "Uploading: #{gzipped} in place of #{f} saving #{percentage}%" else percentage = ((original_size.to_f/gzipped_size.to_f)*100).round(2) - STDERR.puts "Uploading: #{f} instead of #{gzipped} (compression increases this file by #{percentage})" + STDERR.puts "Uploading: #{f} instead of #{gzipped} (compression increases this file by #{percentage}%)" end else STDERR.puts "Uploading: #{f}" From b75d50d0894a459fd6e0ea13f538c13cb2f1536a Mon Sep 17 00:00:00 2001 From: David Rice Date: Sat, 5 Nov 2011 22:16:15 +0000 Subject: [PATCH 18/23] Add todo --- lib/asset_sync/storage.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 844c543..0c65343 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -54,6 +54,7 @@ def delete_extra_remote_files end def upload_file(f) + # TODO output files in debug logs as asset filename only. file = { :key => f, :body => File.open("#{path}/#{f}"), From f8031b755c697086b3349dd22a00931348668088 Mon Sep 17 00:00:00 2001 From: David Rice Date: Sun, 6 Nov 2011 00:05:20 +0000 Subject: [PATCH 19/23] Update gemspec --- asset_sync.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asset_sync.gemspec b/asset_sync.gemspec index 5651b5a..049937f 100644 --- a/asset_sync.gemspec +++ b/asset_sync.gemspec @@ -6,12 +6,12 @@ require "asset_sync/version" Gem::Specification.new do |s| s.name = "asset_sync" s.version = AssetSync::VERSION - s.date = "2011-08-30" + s.date = "2011-11-05" s.platform = Gem::Platform::RUBY s.authors = ["Simon Hamilton", "David Rice"] s.email = ["shamilton@rumblelabs.com", "me@davidjrice.co.uk"] s.homepage = "https://github.com/rumblelabs/asset_sync" - s.summary = %q{Synchronises Assets between Rails and S3} + s.summary = %q{Synchronises Assets in a Rails 3 application and S3/Cloudfront} s.description = %q{After you run assets:precompile your assets will be synchronised with your S3 bucket, deleting unused files and only uploading the files it needs to.} s.rubyforge_project = "asset_sync" From 59e78c405bd2ccb0edf1ba94225d6dbd571bdea2 Mon Sep 17 00:00:00 2001 From: David Rice Date: Sun, 6 Nov 2011 00:16:19 +0000 Subject: [PATCH 20/23] Add gzip compression info to generated asset_sync.rb or .yml. Fix .yml example with new config settings --- .../asset_sync/templates/asset_sync.rb | 5 ++++- .../asset_sync/templates/asset_sync.yml | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/generators/asset_sync/templates/asset_sync.rb b/lib/generators/asset_sync/templates/asset_sync.rb index 2a24e5f..9634cbc 100644 --- a/lib/generators/asset_sync/templates/asset_sync.rb +++ b/lib/generators/asset_sync/templates/asset_sync.rb @@ -2,6 +2,9 @@ config.aws_access_key = ENV['AWS_ACCESS_KEY'] config.aws_access_secret = ENV['AWS_ACCESS_SECRET'] config.aws_bucket = ENV['AWS_BUCKET'] - # config.aws_region = "eu-west-1" config.existing_remote_files = "keep" + # Increase upload performance by configuring your region + # config.aws_region = "eu-west-1" + # Automatically replace files with their equivalent gzip compressed version + # config.gzip_compression = true end \ No newline at end of file diff --git a/lib/generators/asset_sync/templates/asset_sync.yml b/lib/generators/asset_sync/templates/asset_sync.yml index 9770f2a..8213020 100644 --- a/lib/generators/asset_sync/templates/asset_sync.yml +++ b/lib/generators/asset_sync/templates/asset_sync.yml @@ -1,27 +1,30 @@ defaults: &defaults - access_key_id: "<%= aws_access_key %>" - secret_access_key: "<%= aws_access_secret %>" + aws_access_key: "<%= aws_access_key %>" + aws_access_secret: "<%= aws_access_secret %>" # You may need to specify what region your S3 bucket is in - # region: "eu-west-1" + # aws_region: "eu-west-1" existing_remote_files: keep + # Automatically replace files with their equivalent gzip compressed version + # gzip_compression = true + development: <<: *defaults - bucket: "<%= app_name %>_development" + aws_bucket: "<%= app_name %>_development" # Existing pre-compiled assets on S3 will be kept # existing_remote_files: keep test: <<: *defaults - bucket: "<%= app_name %>_test" + aws_bucket: "<%= app_name %>_test" staging: <<: *defaults - bucket: "<%= app_name %>_test" + aws_bucket: "<%= app_name %>_test" production: <<: *defaults - bucket: "<%= app_name %>_production" + aws_bucket: "<%= app_name %>_production" # Existing pre-compiled assets on S3 will be deleted # existing_remote_files: delete From bccc6f9d91447a7bc16bd36a231a68600d47905b Mon Sep 17 00:00:00 2001 From: David Rice Date: Sun, 6 Nov 2011 00:18:13 +0000 Subject: [PATCH 21/23] Add spec to test config defaults gzip_compression to false --- spec/asset_sync_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/asset_sync_spec.rb b/spec/asset_sync_spec.rb index 997a6c8..0707790 100644 --- a/spec/asset_sync_spec.rb +++ b/spec/asset_sync_spec.rb @@ -39,6 +39,10 @@ AssetSync.config.existing_remote_files.should == "keep" end + it "should default gzip_compression to false" do + AssetSync.config.gzip_compression.should be_false + end + end @@ -69,6 +73,10 @@ AssetSync.config.existing_remote_files.should == "keep" end + it "should default gzip_compression to false" do + AssetSync.config.gzip_compression.should be_false + end + end describe AssetSync, 'with no configuration' do From 454b0fe28ad71fe4f1123f16ee74bea468eebe22 Mon Sep 17 00:00:00 2001 From: David Rice Date: Sun, 6 Nov 2011 00:19:58 +0000 Subject: [PATCH 22/23] Add note about gzip_compression --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cee5129..4d86b3c 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,8 @@ Or add to a traditional unix system * **aws\_access\_key**: your Amazon S3 access key * **aws\_access\_secret**: your Amazon S3 access secret * **aws\_region**: the region your S3 bucket is in e.g. *eu-west-1* -* **existing_remote_files**: what to do with previously precompiled files, options are **keep** or **delete** +* **existing\_remote\_files**: what to do with previously precompiled files, options are **keep** or **delete** +* **gzip\_compression**: when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. ## Amazon S3 Multiple Region Support From b62215618a1df1c3d987cf895fa268c5273fbe23 Mon Sep 17 00:00:00 2001 From: David Rice Date: Sun, 6 Nov 2011 00:26:32 +0000 Subject: [PATCH 23/23] Document gzip compression --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d86b3c..291b4dd 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,14 @@ Or add to a traditional unix system * **aws\_access\_secret**: your Amazon S3 access secret * **aws\_region**: the region your S3 bucket is in e.g. *eu-west-1* * **existing\_remote\_files**: what to do with previously precompiled files, options are **keep** or **delete** -* **gzip\_compression**: when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. +* **gzip\_compression**: when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. + +## Automatic gzip compression + +With the `gzip_compression` option enabled, when uploading your assets. If a file has a gzip compressed equivalent we will replace that asset with the compressed version and sets the correct headers for S3 to serve it. For example, if you have a file **master.css** and it was compressed to **master.css.gz** we will upload the **.gz** file to S3 in place of the uncompressed file. + +If the compressed file is actually larger than the uncompressed file we will ignore this rule and upload the standard uncompressed version. + ## Amazon S3 Multiple Region Support