Download the PHP package spekkionu/assetcachebuster without Composer
On this page you can find all versions of the php package spekkionu/assetcachebuster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package assetcachebuster
Asset Cache Buster
This package prefixes asset urls with md5 hashes so that changing the hash results in the url for all asset files to change. This forces browsers to download new versions of the asset files before the browser cache is expired.
This is especially useful when using a CDN that sets far future expires headers on files.
It works with any static files like stylesheets, javascript files, and images.
Installation
The 2.x branch is only compatible with Laravel 5.x. If you need Laravel 4.x compatibility use the 1.x branch.
Add spekkionu\assetcachebuster
as a requirement with composer:
If you have disabled automatic package discovery you will need to register the service provider with the application.
Open up config/app.php
and find the providers
key.
If you have disabled automatic package discovery you will need to register the facade in order to generate an asset url.
You can register the facade via the aliases
key of your config/app.php
file.
There are other packages that want to register the Asset facade. If this is the case you can change the Asset key to be something else to prevent a collision.
For the asset urls to function the following will need to be added to the apache .htaccess file. Add the following to your .htaccess file before the Laravel rewrite rule:
For Nginx, add the following to your virtual host file
Configuration
In order to generate new hashes to invalidate the cache you must publish the package configuration by running the following artisan command.
This will create a config file at config/assetcachebuster.php
Use this file to configure the package.
Set the enabled
flag in the config to true
in order for asset urls to be prefixed.
Usage
For any asset urls you want to be able to cache you must use the Asset::url($url)
facade rather than directly outputting the url.
For example if you wanted to link to a stylesheet located at /css/stylesheet.css
you would add the following to your view
If you are using a blade template the following will work instead.
Invalidating the Cache
To generate a new hash to invalidate caches and force browsers to download new versions of asset files run the following artisan command.
This will generate a new hash and update the config file. It is important that you do not change the hash line of the config file manually or this command may no longer function. If you must manually update the hash make sure it is a valid md5 hash or exceptions will be thrown when generating a hashed url. A md5 hash is a 32 character string with only the characters 0-9 and a-f.
Using with a CDN
To use with a CDN such as Cloudfront set the cdn key in the config to the cdn url.
Now any asset url will begin with the cdn url.
This will only work with a CDN that supports origin pull as it does not push any asset files to the cdn.
Setting Far Future Expires Headers
In order to actually receive a benefit from the package asset files should be set with far future expires headers.
To do this add the following to your apache .htaccess file.
You might need to configure your cdn to set these headers if you are using one.
For Nginx, add the following to your virtual host file