Serve GZip CSS and JS from AWS S3

Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases, such as websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics.

If you are looking to gzip your static JS and CSS when hosting on S3, however, it’s not obvious how to do so, and results often bring up other AWS hosting services as well. Here’s the quick and simple way to serve gzipped JS and CSS from AWS S3.

S3 needs those files compressed before they are uploaded, it can’t do the actual gzipping for us. This is done with a simple command, which I recommend be added as a script to your build step, or your continuous integration process.

gzip -9 /filepath/bootstrap.js or gzip -9 /filepath/bootstrap.css

The -9 denotes that we want the highest level of compression. Now we need to upload the files to AWS S3. While doing this, there is an option to add Metadata, we need to make content type as text/css or text/javascript based on file and content Encoding as gzip.

This is how you can serve Gzipped files from AWS S3. Thanks for dropping by !!! Feel free to comment to this post or you can also reach me at naik899@gmail.com

The post Serve GZip CSS and JS from AWS S3 appeared first on Ravindra Naik.

Comments

Popular posts from this blog

Create a calendar invite (ics file) in ASP NET