Allow gzip for existing files

I have static assets stored in GCS and I would like to serve them gzipped (but they were loaded without compression). Is there a way to install compressed files without downloading and re-downloading them in gzipped format?

I tried to set the content encoding header using gsutil (i.e. gsutil setmeta -h 'Content-Encoding:gzip' <some_object_uri> , but it just resulted in an "unavailable service" in the file (which I assume is from the server, trying to deploy the file and crashing or something else like this).

+5
source share
1 answer

It is not possible to compress objects without loading and reloading them.

However, you can use gsutil for this, and if you run it from the Google Compute Engine (GCE) virtual machine, you will only pay for the number of operations, not the bandwidth.

In addition, regarding the setting of the content encoding header using setmeta , you are correct in your interpretation of what happened. You set the metadata of the object, indicating that it contains gzip data, but the content does not contain a valid gzip stream, so when you try to download it using Accept-Encoding: gzip , the GCS service tries to unzip the stream and does not work.

I would suggest downloading the bucket to a local disk on the GCE virtual machine:

 gsutil cp -r gs://bucket /path/to/local/disk 

Then use the -z option to specify which file extensions are for gzip:

 gsutil cp -z js,css,html -r /path/to/local/disk gs://bucket 
+4
source

Source: https://habr.com/ru/post/1205520/


All Articles