3

I am using Google Cloud Storage console to upload files. I am not using any command line tool. I want to Set the Content-Encoding to gzip (-z option) in Metadata.

Please see below screenshot, is value 'z' is correct or not?

enter image description here

I have set value 'z' for all css and js files, and analyzed webpage on PageSpeed Insights. PageSpeed Insights still telling me enable compression, please check below screenshot.

enter image description here

I am using Nginx webserver with HttpGzipModule installed on Debian 7.

Thanks.

falsarella
  • 12,217
  • 9
  • 69
  • 115
Hrishi
  • 169
  • 3
  • 10

3 Answers3

12

"-z" is a feature of the gsutil command line tool -- it compresses the data locally and uploads it to GCS with Content-Encoding: gzip. It is not a feature (or property) of the HTTP protocol or Google Cloud Storage, hence simply setting the header does not achieve what you are going for.

If you want to store (and serve) gzip-encoded data, you have two options:

  1. Apply gzip-compression locally, for instance with the gzip Unix tool. Then remove the .gz suffix from the file name and upload it with the "Content-Encoding: gzip" header and the appropriate Content-Type (e.g., "text/css" for css, "application/javascript" for js).
  2. Use the gsutil tool with the -z flag, and it will take care of all of the above for you.
lot
  • 1,045
  • 1
  • 8
  • 8
0

If you are using the Google Cloud SDK (eg: Java, Go, etc) instead of the CLI you can also enable a gzip setting.

For example in JavaScript:

bucket.upload('data.json', {
    destination: 'data.json',
    gzip: true
});

https://cloud.google.com/storage/docs/uploading-objects

Pier
  • 10,298
  • 17
  • 67
  • 113
0

Using the Google Cloud SDK in C#, there are two overloads for the UploadObject method.

You need to use the overload that takes a Google.Apis.Storage.v1.Data.Object and a Stream as parameters.

The example below assumes a json file compressed with gzip into a stream:

var objectToBeCreated = new Google.Apis.Storage.v1.Data.Object
{
    Bucket = "bucketName",
    Name = "objectName",
    ContentType = "application/json",
    ContentEncoding = "gzip"
};

var uploadedObject = storageClient.UploadObject(objectToBeCreated, stream);

bounav
  • 4,886
  • 4
  • 28
  • 33