如何在AWS CloudFront上启用gzip压缩 [英] How to enable gzip compression on AWS CloudFront
问题描述
我试图gzip压缩通过 CloudFront
提供的img。我的出身是 S3
I m trying to gzip compress the img I m serving through CloudFront
. My origin is S3
根据有关AWS的几篇文章/博客,我所做的是:
Based on several articles/blogs on aws, what I did is:
1)为要压缩的对象设置 Content-Length
标头。我将值设置为等于 size
属性框上出现的大小
1) Set "Content-Length"
header for the object I want to compress. I set the value equal to the size appeared on the size
property box
2)设置在我的云分布的
的值为行为
中,将对象自动压缩是
。
2) Set the Compress Objects Automatically
value to Yes
in the Behaviour
of my cloud distribution.
3)我使我的对象无效,无法从 S3
获得新副本。
3) I invalidated my object to get a fresh copy from S3
.
仍然无法将 CloudFront
gzip用作我的对象。有想法吗?
Still I m not able to make CloudFront
gzip my object. Any ideas?
推荐答案
我正在尝试gzip压缩[image]
I'm trying to gzip compress the [image]
通常不需要gzip图像-这样可以节省很少的带宽(如果有的话),因为实际上网络上使用的所有图像格式都是
You don't typically need to gzip images -- doing so saves very little bandwidth, if any, since virtually all image formats used on the web are already compressed.
此外,CloudFront不支持它。
Also, CloudFront doesn't support it.
请参见 CloudFront压缩的文件类型用于支持的文件格式。它们是基于文本的格式,通常会从gzip压缩中受益匪浅。
See File Types that CloudFront Compresses for the suported file formats. They are text-based formats, which tend to benefit substantially from gzip compression.
如果您真的希望将文件压缩后,可以存储
If you really want the files served gzipped, you can store the files in S3, already gzipped.
$ gzip -9 myfile.png
这将创建一个压缩文件 myfile.png.gz
。
This will create a gzipped file myfile.png.gz
.
将文件上传到S3 最后而没有.gz。将 Content-Encoding:
标头设置为 gzip
并设置 Content-Type:
标头指向文件的正常正确值,例如 image / png
。
Upload the file to S3 without the .gz on the end. Set the Content-Encoding:
header to gzip
and set the Content-Type:
header to the normal, correct value for the file, such as image/png
.
这会破坏所有不理解 Content-Encoding:gzip
的浏览器,但是使用的浏览器不应有该限制。
This breaks any browser that doesn't understand Content-Encoding: gzip
, but there should be no browsers in use that have that limitation.
请注意,上面的 -9
表示最大压缩。
Note that the -9
, above, means maximum compression.
这篇关于如何在AWS CloudFront上启用gzip压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!