简体   繁体   English

如何在AJAX请求期间启用Google Storage gzip

[英]How to enable Google Storage gzip during AJAX request

I'm accessing JSON files stored in a bucket on Google Storage directly using an AJAX request. 我正在使用AJAX请求直接访问Google存储桶中存储的JSON文件。 However to optimize the communication I want to enable gzip encoding. 但是,为了优化通信,我想启用gzip编码。

The docs say I have to send an Accept-Encoding header and an altered User-Agent (containing gzip). 文档说我必须发送一个Accept-Encoding标头和一个更改的User-Agent(包含gzip)。 Accept-Encoding is no problem, however altering your User-Agent is not possible, the w3c even specifies so. Accept-Encoding没问题,但是无法更改User-Agent, w3c甚至指定了这一点。

How can I still enable gzipping while doing these request? 执行这些请求时,如何仍然启用gziping?

If you'd like to download your files with gzip encoding, they need to be stored in Google Cloud Storage with that encoding already applied, as well as with the appropriate metadata (Content-Encoding: gzip and proper content type, in this case Content-Type: application/json). 如果您想使用gzip编码下载文件,则需要使用已应用的编码以及适当的元数据(Content-Encoding:gzip和适当的内容类型,在本例中为Content)将文件存储在Google Cloud Storage中。 -类型:application / json)。 If you subsequently request these objects with the Accept-Encoding: gzip request header, GCS will serve them with gzip encoding. 如果您随后使用Accept-Encoding:gzip请求标头请求这些对象,则GCS将使用gzip编码为它们提供服务。

Edited to add: "gzip" in the user agent string is no longer required (but doesn't hurt either) -- I've requested that the docs be updated accordingly. 编辑为:不再需要在用户代理字符串中添加 “ gzip”(但也不会造成伤害)-我已要求对文档进行相应的更新。

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

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