How do I enable gzip compression on Spaces?

Posted June 12, 2019 1.6k views

(I’m referring to the DigitalOcean Spaces + CDN Product)

How do I enable gzip compression on web assets that I have in my Space and using a CDN for? I’ve defined the Content-Encoding value to gzip and flushed the cache but it hasn’t worked.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

7 answers

Shame on you, digitalocean.

it’s 2019 and there is no gzip? Really?

Your “CDN” is useless, there is no way to serve static files. So why does it need for?

Hey, did you find any solution?
For me Gzip encoding is only work when in origin link.

Same for me compression breaks Javascript files.


This has been discussed before, but from what I know, gzip compression is not fully supported on the Spaces CDN. This is most likely off to ensure the most compatability of end users who pull resources from the CDN. Even though most browsers across many devices support gzip.

You can also open a ticket wit their support team and they can fully explain if gzip compression is switched off or just some static content is compressed by default or if they’re using something else on their end.

Let us know how it goes.


This is the main blocker from us moving from cloudfront to Space to serve our static files

Yeah… this kinda sucks. Should be a simple setting for us to gzip at the server level.

I know this is very sub-optimal, but I wrote a simple js code to gzip js files before pushing it to Spaces.

const gzipme = require('gzipme');
gzipme('filename', true); // true means overwrite on the file.
                    Bucket: bucketName,
                    Key: 'filename',
                    Body: base64data,
                    ACL: 'public-read',
                    ContentType: 'application/javascript;charset=utf-8', 
                    ContentEncoding: 'gzip', // important
                    CacheControl: 'max-age=86400' // optional
                }, function (resp) {
                    console.log('Successfully uploaded file:');

After doing this for all of my files, I purge CDN cache.

It works for me so far.

  • “I know this is very sub-optimal, but I wrote a simple js code to gzip js files before pushing it to Spaces.”

    It doesn’t work, even with pre-gzipped files cdn doesn’t send Encoding gzip header and thus browser is not able to automatically unzip the content.

    • If you set ContentEncoding to ‘gzip’ , Spaces send this in the header, thus browser can successfully unzip it. That’s why I put “important” there.

Submit an Answer