How to handle small files for DO's Spaces performance?

July 16, 2019 146 views
DigitalOcean Object Storage Ubuntu 18.04

I'm using Spaces to host image assets with small file sizes, hanging from 5kb to 50kb.

From what I've seen in the "Improve DO Spaces Performance" tutorial, this is an issue, but it doesn't tell how to handle this situation and I had no luck searching on google.

I simple use <img src="spaces-cdn-url-for-file">.

How can I pack the images into some bigger files and make the web app unpack and use them?

PS: It's a rails app.

1 Answer

One of the main reasons to use webpack would be to decrease the number of requests to a CDN or web server to load images, but usually it's not worth the overhead. With webpack the images are encoded in base64 strings and then inserted directly into the code where they are then rendered.

For your use case I would recommend that you just turn on the CDN option with your Spaces folder:
Enable CDN for Spaces

And you should be good to go without having to worry about webpack.

With the CDN your images will be cached at the edge and will load quickly. Beyond that it's usually overkill unless you are dealing with millions of requests.

Have another answer? Share your knowledge.