GCS (Google Cloud Storage) is a good free CDN to store static web resources, in one of my use case I use it to store large JSON text files that will be downloaded by client web.
Because the JSON text files' size are large, therefore I need to reduce the files' size to faster the download and reduce internet data usage for smartphone. Luckily there is a way to do this for JSON text file stored in GCS, below is the simple steps.
- Compress the JSON text file using 'gzip', only gzip is allowed (not tar nor zip nor other compression format), because gzip is a "standard" compression that is supported by GCS and Ajax call.
Example command of how to compress a JSON file and create different filename output.gzip -9 -c obf2-en-amp_2024-09-30_22-35-03.json > obf2-en-amp_2024-09-30_22-35-03.json.gz
- Upload the gzip-compressed files to GCS (because it is rarely updated so I upload them to GCS in GCS's console drag-and-drop).
- Change the metadata of each file, by default GCS will automatically recognize them and set the "Content-Type" as "application/gzip", so we need to change the "Content-Type" = "application/json" and "Content-Encoding" = "gzip"
That's it, if everything is configured properly then we can try to use Chrome/Firefox browser to directly open the JSON file by entering its public URL, we can see the JSON text content properly instead of gzip binary content.