CloudFront with S3 website as origin is not serving gzipped files

前端 未结 2 1961
野的像风
野的像风 2020-12-14 07:14

AWS now supports gzipping files through CloudFront

I\'ve followed along with all of the instructions in Serving Compressed Files, and yet gzipping is not working.

相关标签:
2条回答
  • 2020-12-14 07:37

    My problem was that I uploaded the files specifically with utf-8 encoding. From the documentation:

    CloudFront determines whether the file is compressible:

    The file must be of a type that CloudFront compresses.

    The file size must be between 1,000 and 10,000,000 bytes.

    The response must include a Content-Length header so CloudFront can determine whether the size of the file is in the range that CloudFront compresses. If the Content-Length header is missing, CloudFront won't compress the file.

    The response must not include a Content-Encoding header.

    0 讨论(0)
  • 2020-12-14 07:41

    I hit the same error today and solved it by adding a CORS rule to the S3 bucket. This rule ensures the Content-Length header is sent to Cloudfront so content can be gzipped:

    S3 > Bucket > Permissions > CORS Configuration

    <?xml version="1.0" encoding="UTF-8"?>
    <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
        <CORSRule>
            <AllowedOrigin>*</AllowedOrigin>
            <AllowedMethod>GET</AllowedMethod>
            <MaxAgeSeconds>3000</MaxAgeSeconds>
            <AllowedHeader>Authorization</AllowedHeader>
            <AllowedHeader>Content-Length</AllowedHeader>
        </CORSRule>
    </CORSConfiguration>
    

    Credit goes to Robert Ellison: http://ithoughthecamewithyou.com/post/enable-gzip-compression-for-amazon-s3-hosted-website-in-cloudfront

    As far I know, this seems to be an undocumented requirement.

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