I have a blog built with astro.js, where most of my posts are markdown files that are part of the source code. Many of these posts include media like images and videos, but I want to avoid including these files in my source code because they can make the repository bloated. Given that I'm hosting on Cloudflare Pages, what are the best practices for handling media files?
6 Answers
If you're thinking about a digital asset manager, check out some useful resources. They can simplify how you manage media assets; here's a helpful article on what a DAM can do for you.
It's best to keep your media files separate from your source code to avoid repository bloat. Since you're using Cloudflare Pages, consider using Cloudflare R2, which is their S3-compatible object storage. You can upload your images and videos there, organize them however you like, and serve them through Cloudflare's CDN for speedy access. Just link to them in your markdown using full URLs to keep your project clean and ensure scalability. For smaller blogs, putting assets in the /public folder could suffice, but for growth, R2 plus a CDN is a solid choice.
Using Cloudflare Images or R2 is a smart move to host your media separately from your source code. Just reference those media URLs in your markdown to keep everything lightweight and leverage Cloudflare's CDN for speed.
I've had great success using a headless CMS, like Prismic. It’s backed by AWS but is much simpler to use, especially if you're managing a lot of media files.
Are you looking just for simple hosting, or do you want a service that optimizes your content too? If you're after optimization, take a peek at Cloudinary. They've got great integration with Astro, and it can really help enhance your media handling!
That's interesting! I hadn't thought about optimization but it could really improve load times.
Another option to consider is offloading your media to a CDN or an object storage service. You might want to look at Cloudflare R2, Bunny.net (which is super fast and affordable), or even Imgur and Cloudinary for images. For tight integration with Cloudflare Pages, R2 stands out since you can easily keep your repo lightweight and still serve your media efficiently.

I get that, but isn't it overkill for smaller projects? Why not just use a basic VPS with Cloudflare for CDN instead of jumping through hoops?