We've long wanted a way to utilise a CDN to offload images/files/videos from ProcessWire sites without losing all the native greatness of ProcessWire image and file field types.
Having read various discussions on here about ways to approach this that never seemed to reach conclusion, I've thrown myself into creating a module that allows offloading of files to Bunny.net CDN as we need a solution for a specific project.
I think this would be easily adaptable to any S3 compatible CDN but I've only tested on Bunny.
⚠️ This is still very beta! Use at your own risk!
I've been conducting basic testing and so far, so good but there's bound to be holes or things that others may suggest better ways of doing. But I'm now at a stage where the insight/experience of the PW community might add value to the project - so I'm sharing now!
Full disclosure: Once past the initial project scaffolding I've been using AI/careful prompting to write some of the code so that I can arrive at a prototype as quickly as possible. This seems to have worked well, although some of the code looks a little verbose and could probably be refactored later on. Also not security/pen-tested yet.
https://github.com/warp-design/WireBunnyCdn/
Features:
Automatically uploads images to Bunny storage on page save, including all variants and mirrors assets folder structure for simple merging back to local at a later date if needed.
Automatically cleanses deleted files (or files from deleted pages) from your CDN.
Option to mirror files to CDN or delete local copies (this is the main aim for me, otherwise we could just use ProCache).
Handles (basic currently) image sizing - either using standard ProcessWire `$image->size(X,X)` methods or by implementing Bunny Optimizer for sizing using URL params.
Rewrites image paths via CDN so that you can use standard `$page->imageField->url` calls with the output being a Bunny path rather than local PW path. Also handles the image previews in admin view.
Roadmap:
Support for video uploads (with optional separate CDN endpoint for Bunny Stream buckets).
Support for front-end video output to templates using Bunny stream players/optimisation etc.
Implement chunked/background uploads for large files.
Support for other size() method options, like cropping etc and mapping to Bunny Optimizer equivalents.
Anyway - look forward to hearing any advice/feedback/bug reports... I'm sure there's many!