如何在 Google 云存储上为 SVG 图像启用 Gzip 压缩?

How to Enable Gzip Compression for SVG Images on Google Cloud Storage?

使用 Google Pagespeed Insights 检查我的网站时,我收到以下警告:

Enable compression Compressing resources with gzip or deflate can reduce the number of bytes sent over the network. Enable compression for the following resources to reduce their transfer size by 2.9KiB (56% reduction). Compressing https://MY_BUCKET.storage.googleapis.com/logo.svg could save 561B (49% reduction).

似乎Google Cloud Storage 没有为 svg 启用 gzip? 如何为 svg 文件类型启用 gzip 压缩?

结果你必须手动压缩 svg:

gzip -9 -S 'z' *.svg

然后使用 Content-Encoding 上传:

gsutil -h "Content-Encoding:gzip" -h "Content-Type:image/svg+xml" cp logo.svgz gs://MY_BUCKET/logo.svgz

来源:https://cloud.google.com/storage/docs/gsutil/addlhelp/WorkingWithObjectMetadata#content-encoding

更新:

这结合了上述两个命令,如@jterrace

所述
gsutil -h "Content-Encoding:gzip" -h "Content-Type:image/svg+xml" cp -Z logo.svg gs://MY_BUCKET/logo.svg