Can someone walk me through serving gzipped files from Cloudfront via S3 origin?

后端 未结 1 1654
情话喂你
情话喂你 2021-01-07 02:07

I\'ve been through quite a few suggestions given on this topic from other posts on Stackoverflow, but I\'m still not successfully getting it to work.

The website or

相关标签:
1条回答
  • The process should look like this:

    • gzip the file locally (it should then be called index.html.gz)
    • remove the .gz extension (file is now called index.html but content is gzipped)
    • upload the file to S3
    • in the metadata tab for the file in the S3 management console set the correct Content-Type based on what file it is and
    • set Content-Encoding to gzip

    When linking to a gzipped stylesheet in your HTML markup just specify the name without the .gz extension.

    A great site to test if the configuration works is http://gzipwtf.com/

    Also don’t forget to invalidate the CloudFront cache if the file you’re trying it out with is cached.

    edit:

    To not fiddle around with this stuff by hand all the time I suggest you automate the process of uploading and setting headers in some kind of build process. s3_website is a nice Ruby gem to get started but there are other command line tools or Grunt plugins available as well.

    0 讨论(0)
提交回复
热议问题