简体   繁体   中英

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. However to optimize the communication I want to enable gzip encoding.

The docs say I have to send an Accept-Encoding header and an altered User-Agent (containing gzip). Accept-Encoding is no problem, however altering your User-Agent is not possible, the w3c even specifies so.

How can I still enable gzipping while doing these request?

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). If you subsequently request these objects with the Accept-Encoding: gzip request header, GCS will serve them with gzip encoding.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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