Laxman More
Laxman More

Reputation: 307

gzip not working for aws s3 assets

I have uploaded javascript file to aws s3 bucket and for gzip compression, I have set following meta data. Also I have made file as public.

Content-Encoding: gzip

There is already one meta data is there

Content-Type: application/x-javascript

Error when accessing from browser

This webpage is not available ERR_CONTENT_DECODING_FAILED

Accessing url like this

https://s3-url.amazonaws.com/bucket-name/assets/js/angular.js

Upvotes: 1

Views: 2167

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179414

Setting Content-Encoding: gzip doesn't actually change your object's content encoding. This is used to describe the encoding you have applied.

Setting it without actually applying gzip compression to the object will lead to errors like the one you encountered. This is the browser complaining that you "claimed" (via the header) that the content was actually encoded with gzip, when in fact it wasn't.

Similarly, uploading a gzipped object without setting the header will result in an unusable download since the receiving user agent (browser) has no way to know how to decode the content, or that it even should try.

Note that when you gzip a file on your computer using gzip -9 somefile.js its name changes to add .gz onto the end, leaving its name as somefile.js.gz. Remove the .gz, before uploading. It isn't needed and of course you don't want to have to change your links.

The -9 above specifies that gzip should use maximum compression, which is probably what you want.

Upvotes: 4

Related Questions