f_roepstorf/static-cache-buster
A Laravel package that busts browser and CDN caches for static assets by appending versioned query strings or hashes, ensuring updated CSS, JS, and images load immediately after deployment without manual cache clearing.
This package targets a specific Statamic pain point: after content changes or a deploy, static caches are invalidated and the next visitor pays the cost of regenerating the page. The package warms those pages ahead of traffic so visitors never hit the uncached path.
Minimal steps:
config/statamic/static_caching.php, strategy set to half or full):
composer require f_roepstorf/static-cache-buster
php artisan vendor:publish --tag=static-cache-buster-config
php artisan list | grep -i -E "cache|warm|buster"
ls vendor/f_roepstorf/static-cache-buster/src
Read the service provider to see whether it registers commands, listeners, or a queue job — that dictates how you wire it in.APP_URL matches the host you actually serve, and that the warm requests can reach the front end unauthenticated.Where to look first: the package's README, its service provider, and config/static-cache-buster.php after publishing. Those three files tell you the command name, config keys, and whether it hooks into Statamic's cache-invalidation events automatically.
First use case: a post-deploy warm. Instead of letting the first users after a deploy absorb cold-start latency, run a warm step at the end of your deploy pipeline against the origin (not the CDN), then let traffic in.
The highest-leverage use is a deploy step. Warm against the origin host directly, so you don't pollute the CDN edge with half-warmed responses:
# after artisan migrate / config:cache, before flipping traffic
php artisan <package-warm-command> --url="${ORIGIN_URL}"
Keep this step time-boxed. If warming takes longer than your deploy budget, move it to a queued job or a scheduled command instead of blocking releases. A warm that runs for 20 minutes is worse than a cold cache.
Statamic fires save events for content. The idiomatic pattern is to queue a re-warm for the affected URL rather than warming the whole site:
use Illuminate\Support\Facades\Queue;
use Statamic\Events\EntrySaved;
Event::listen(function (EntrySaved $event) {
$uri = $event->entry->uri();
Queue::push(function () use ($uri) {
// Warm just this URL via the package's warmer/command
Artisan::call('<package-warm-command>', ['--url' => url($uri)]);
});
});
Two rules of thumb:
ShouldBeUnique on the job or coalesce per-URL warm requests within a short window.For scheduled warming (nightly, or after large imports), drive the URL list from your sitemap rather than hand-maintaining a list:
$urls = collect(explode("\n", file_get_contents(public_path('sitemap.xml'))))
->filter(fn ($line) => str_contains($line, '<loc>'))
->map(fn ($line) => trim(strip_tags($line)))
->filter();
Warm those URLs with bounded concurrency — the package's config usually exposes something like concurrency, timeout, and bypass headers. Start at low concurrency (2–4) against a single origin.
Some Statamic static-cache setups will serve an existing cached file before your request reaches the app, which means your "warm" is a no-op. Check whether the package (or Statamic's middleware) supports a bypass header and send it if you need to force regeneration:
curl -s -o /dev/null -w "%{http_code} %{time_total}\n" \
-H "X-Statamic-Static-Cache: bypass" \
https://origin.example.com/about
Confirm the exact header name in the package/Statamic source for your version — it has changed across Statamic versions.
Don't trust exit codes. Assert on the result:
# First request after invalidation should be fast AND have the cache header set
curl -sI https://origin.example.com/about | grep -i static-cache
Also watch the cache directory (storage/statamic/static for full strategy, or your configured path) before and after to confirm files appear.
Warming is usually pointless in local dev and can mask cache-miss bugs. Gate it behind an environment check or only run it in production/staging so you still see real cold-cache behavior while developing.
src/ for anything dangerous (arbitrary HTTP calls, unserialize, shelling out), and be prepared to fork. Treat it closer to a snippet than a dependency.Authorization header, you can cache a personalized or logged-in page. Use a clean, unauthenticated HTTP client.half, cached pages still hit the app middleware; with full, Statamic writes and serves flat files. Confirm what "warm" means in each mode — for full, the file must exist on disk; for half, the response cache entry must be populated./login or swallows 404s will report success while caching nothing useful. Capture the status code per URL and fail loudly on unexpected codes.?utm_source=... variants wastes requests.How can I help you explore Laravel packages today?