Using GZIP with html pages served from Amazon S3

2019-02-02 13:09发布

问题:

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?

回答1:

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

Content-Encoding=gzip


回答2:

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.