简体   繁体   English

React,S3,CloudFront压缩。 邮编

[英]React, S3, CloudFront Compression. GZip

I am trying to get my PageSpeed score as close to 100 as possible. 我正在尝试使我的PageSpeed得分尽可能接近100。 One of the suggestions I got from https://developers.google.com/speed/pagespeed/insights is that I should enable compression. 我从https://developers.google.com/speed/pagespeed/insights获得的建议之一是我应该启用压缩功能。

This is where I am a bit confused. 这是我有点困惑的地方。 I was under the impression that I already had compression enabled. 我的印象是我已经启用了压缩。 In CloudFront, I have the compress objects automatically behavior enabled. 在CloudFront中,我启用了compress对象自动行为。

在此处输入图片说明

Upon doing some reading here: 在这里阅读后:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

it looks as though you need to include the header Accept-Encoding: gzip. 好像您需要包含标头Accept-Encoding:gzip。 However, when I look at my request I can see that header present. 但是,当我查看请求时,可以看到该标头存在。

It is serving up a React app I built using create-react-app and I can see that header present with no ejecting or extra configuration. 它正在为我使用create-react-app构建的React应用提供服务,我可以看到该头没有弹出或额外配置。

在此处输入图片说明

However I am still getting the following suggestion from Google's Page Speed test. 但是,我仍然从Google的Page Speed测试中得到以下建议。

在此处输入图片说明

Is there anything more I can do? 我还能做些什么吗? Or a way I can verify that the request is being compressed? 还是我可以验证请求是否被压缩的方法? If it is why is this suggestion still showing up? 如果这是为什么这个建议仍然存在?

Thanks 谢谢

CloudFront determines whether the file is compressible: CloudFront确定文件是否可压缩:

the file size must be between 1,000 and 10,000,000 bytes. 文件大小必须在1,000到10,000,000字节之间。

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

If you compress your 64 Byte file, you have no no advantages, because unzipping takes more time than transfer. 如果压缩64字节文件,则没有任何优势,因为解压缩比传输要花费更多的时间。 Yes, Google PageSpeed Insights doesn't care, but in case of small files, they are wrong. 是的,Google PageSpeed Insights不在乎,但如果文件较小,则它们是错误的。

If you really want to serve a gzipped file, you have to compress it in the origin (eg AWS S3) and set the content-encoding header 如果您确实要提供压缩文件,则必须在源文件中将其压缩(例如,AWS S3)并设置content-encoding标头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM