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

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.