Introducing Varnish Purger for Craft CMS
The rise of AI crawlers has had a massive impact on smaller websites - more traffic means a higher bandwidth bill and a worse experience for regular human users. Over the past 6 months, I've seen this become a bigger and bigger issue at my day job and I've been actively working on our larger projects and with our hosting partner to improve performance.
That same hosting partner bundles a Varnish option into their offering and we weren't really taking advantage of it so I decided to see if I could write a plugin that would make this easier to do.
How it works
Every page that goes into Varnish gets a list of what's on it: which entries, which assets, which sections it lists. When someone saves an entry, the plugin tells Varnish to throw away the pages that have that entry on them, and nothing else. Change an event and the event page and the event overview get refreshed. The homepage stays cached, unless that event is on it of course.
If you've used Blitz, this will sound familiar. Blitz does exactly this, but for its own cache.
Craft already knows what changed
The part I'm happiest with is that I didn't have to write any of the "what does this save affect" logic myself. Craft already has it. When you use {% cache %} in a template, Craft keeps track of which elements and queries were used inside that block, and clears the block when one of them changes. Those are Craft's element cache tags.
The plugin turns on that same tracking while a page renders, and sends the tags along to Varnish in a response header. When Craft says "these tags are invalid now", the plugin sends those tags to Varnish as a ban. So I'm not mimicking Craft's rules, I'm just using them, and {% cache %} and Varnish always agree on what changed.
The plugin is only half the work
Everything else happens in the VCL, and the VCL is where your site actually gets cached or not.
What should never be cached? Your login area, a cart, a page that greets people by name. Which cookies matter? Maybe a cookie consent choice changes what the page looks like, and then Varnish needs to keep a separate copy per choice. Which IP sends the bans? Is there a proxy in front of Varnish, or Cloudflare? Which hostnames does the site run on? None of that is something a plugin can know. It's different for every site and every hosting setup.
So the VCLs in the repo are examples, not a config you can drop in and forget. They're a good starting point, and they handle the parts that are the same everywhere: only caching pages the plugin tagged, checking who sends bans, and not letting visitors mess with headers Craft trusts. But go through them line by line for every site you use them on, and test with real pages before you go live. A VCL that caches too much shows one visitor's page to another. One that caches too little just makes the plugin pointless.
Trying it
You can find the plugin on GitHub, Packagist and the Plugin Store, and the repo has example VCL files that match the plugin's way of working.
The README has the full setup. If you're setting it up with Claude Code, Cursor or similar, point it at AGENTS.md. That file has all the background, hosting pitfalls and a lot more detail, so your agent doesn't have to find them out the hard way like I did.
It's a beta, and every Varnish setup is a bit different, so I'd really like to hear how it works on yours. The code is on GitHub. If something breaks, open an issue.
Tag based cache clearing for Varnish Cache
Free Github