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

Posted July 16, 2019 1.9k views
DigitalOceanObject StorageUbuntu 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.

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.

Submit an Answer
2 answers

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.

I know this is old question. But in the past, I have placed the smaller images into a single image file then used javascript / CSS to move around in that image and only display the image I want. This seriously improved performance of my applications. In a single http request, all my images were pulled at once.