As Clive mentioned there is no config on s3 which could automatically compress the assets on s3.
The way we fixed it in our case was to add cloudflare CDN service(already in use) in front of s3 file system.
In order to route the s3 assets request via CF we added a proxy subdomain for our drupal origin. So if Drupal site was running on site-url.com we added a proxy subdomain as s3-<env>.site-url.com
. We added a page rule in CF to override host to s3 bucket for any request to s3-<env>.site-url.com/*
.
Now, the challenge was to override s3 hostname configuration in Drupal to spit out resources on s3-<env>.site-url.com/*
instead of s3 bucket url.
Big thanks to S3FS module maintainers for providing easy configuration to override that by adding following in settings.php
$config['s3fs.settings']['use_cname'] = TRUE;
$config['s3fs.settings']['domain'] = 's3-<env>.site-url.com';