jeroenvdheuve/assetic-cache-busting-worker
A PHP worker for Assetic that adds cache-busting to asset URLs by appending content-based versions or hashes. Helps prevent stale browser caches after deployments by keeping generated asset references in sync with compiled files.
This package is archived (last release 2015, 0 stars, 0 dependents). The only realistic audience is a team maintaining a legacy Symfony 2.x / Assetic application. If you are starting fresh, stop here and use Symfony Encore, Vite, or Webpack instead — symfony/asset + symfony/webpack-encore-bundle covers cache busting today.
For a legacy app:
"repositories": [{"type": "vcs", "url": "https://github.com/jeroenvdheuvel/assetic-cache-busting-worker"}]
Then composer require jeroenvdheuve/assetic-cache-busting-worker:dev-master.vendor/jeroenvdheuvel/assetic-cache-busting-worker/src/ and open the class that implements Assetic\Factory\Worker\WorkerInterface. There is no documentation shipping with the repo, so the interface methods (process() / getHash()) are your spec.Assetic\Factory\AssetFactory so that every compiled asset gets a content-hash fingerprint appended to its URL, invalidating browser caches on deploy without changing template code.Register on the AssetFactory. Assetic workers run at factory time, before the asset is dumped:
use Assetic\Factory\AssetFactory;
use JeroenVdHeuvel\Assetic\Worker\CacheBustingWorker; // adjust to actual FQCN
$factory = new AssetFactory($rootDir);
$factory->setDebug(false);
$factory->addWorker(new CacheBustingWorker(/* ctor args from source */));
Symfony 2 service overlay. Decorate the assetic.factory service in services.yml rather than instantiating manually:
services:
assetic.factory:
class: Assetic\Factory\AssetFactory
# ... existing args ...
calls:
- [addWorker, ['@app.assetic.cache_busting_worker']]
app.assetic.cache_busting_worker:
class: JeroenVdHeuvel\Assetic\Worker\CacheBustingWorker
Template-side usage stays unchanged. The whole point of a worker is that {% stylesheets %} / {{ asset('...') }} resolve to the busted URL automatically. If you find yourself editing Twig tags to add ?v= by hand, the worker is not registered correctly.
Pair with the core worker as a fallback. Assetic\Factory\Worker\CacheBustingWorker ships in Assetic itself. If this package's behaviour (e.g., a specific hash algorithm or file naming) doesn't match what you need, the bundled one is a known-good substitute and is still maintained.
Run inside the dump pipeline. Ensure assetic:dump executes in your CI/deploy so the hash reflects the built output, not source files. The worker only computes a value; the dump is what produces the fingerprinted artifact.
psr-0 in composer.json. If classes can't be found, check the autoload block and add a psr-4 override via your root composer.json.AssetFactory::addWorker() appends in insertion order; workers run sequentially. If you stack a minifier worker and a cache-buster, verify the buster runs after the minifier so the hash is computed over final content.assetic.debug: true the factory emits un-fingerprinted URLs by design. Test cache busting against dev with debug off, or only in prod.getHash().assetic:dump output is required. Stale fingerprinted files linger in web/ after deploy. Add a rm -rf web/{css,js}/* or assetic:dump --force step.git rev-parse --short HEAD for a build ID), keeping the packaged class as a thin shell.AsseticBundle config keys changed and the assetic.asset_factory service ID may differ — verify with debug:container | grep assetic before wiring.How can I help you explore Laravel packages today?