Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GZIP with html pages served from Amazon S3

Tags:

gzip

amazon-s3

Does anyone know of any problems serving gzipped HTML pages using Amazon S3. I have the need to minimize the file size of our HTML files (ie serving up compressed HTML, CSS and javascript files) - but am concerned that either:

  1. Amazon S3 does not serve up gzipped files correctly to the browser that requests it. Or,

  2. Some browsers have trouble reading gzipped content. I understand older browsers do not support gzipped content (such as IE6 and earlier) - and some (modern?) anti-virus software will strip the content-encoding headers.

Do I need to serve up uncompressed HTML (which I believe Amazon S3 will support easily) - or can I rest assured that most modern browsers will handle my gzipped content okay?

like image 735
Steve Avatar asked Aug 02 '10 01:08

Steve


People also ask

Does S3 support gzip?

Even though Amazon S3 has most of the features of a full-fledged web server, it lacks transparently supporting GZIP. In another way, you have to manually compress the files using GZIP and setup the Content-encoding header to GZIP.

Does Amazon S3 compress?

You can decompress the data when you read data from Amazon S3 or compress data when you write data to Amazon S3. Data Compression is applicable when you run a mapping in the native environment or on the Spark and Databricks Spark engine. option.

How do I enable gzip on AWS?

Configuring CloudFront to compress objects Make sure the Compress objects automatically setting is Yes. (In AWS CloudFormation or the CloudFront API, set Compress to true .) Use a cache policy to specify caching settings, and make sure the Gzip and Brotli settings are both enabled.

Is gzip supported by all browsers?

gzip is commonly supported by web servers and modern browsers, meaning that servers can automatically compress files with gzip before sending them, and browsers can uncompress files upon receiving them.


2 Answers

Gzip the file and add the following metadata entry to the S3 object before uploading it:

Content-Encoding=gzip
like image 67
Tal Avatar answered Sep 30 '22 03:09

Tal


Amazon S3 does not support gzipped content automatically, but you can manually change the content encoding headers before you upload the content. It will dutifully serve the content back as content type gzip. However, if your file extensions are .gz, then safari will treat it like an attachment, so you have to use .jgz as a file extension.

like image 39
Michael Mullany Avatar answered Sep 30 '22 02:09

Michael Mullany