a3gz / assets-dispatcher
Dispatch versioned assets.
Installs: 2 564
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
This package is auto-updated.
Last update: 2024-12-13 07:24:14 UTC
README
Install
composer require a3gz/assets-dispatcher
How to use
Please, check out the included demo.
What does it do?
Assets Dispatcher offers a way to easily minify-and-cache-once Javascript and CSS assets on-the-fly.
The full sized assets don't need to be below public_html
; the PHP dispatcher will:
- Attempt to dispatch a minified version of the requested asset.
- If the above fails, look for the original non-minified file, create the minified version and dispatch the resulting file.
Evidently, Assets Dispatcher isn't the fastest way to serve Javascript/CSS files because even when there's a minified version available, everything is resolved by a PHP program. For this reason the use proposed in the demo may not be a convenient setup.
Assets Dispatcher as an automated minifier
An alternative use we can have for Assets Dispatcher is that of an automated minifier. Please, take a look at demo-alt
for details.
In this setup, instead of using a PHP dispatcher to serve the assets, we use it to generate the minified versions of all the resources. In the demo-alt
we do this via a PHP file that we have to HTTP GET, but in a real situation we would use a cron job instead.