PHPackages                             ejunker/laravel-cachebuster - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. ejunker/laravel-cachebuster

ActiveLibrary[Caching](/categories/caching)

ejunker/laravel-cachebuster
===========================

Adds MD5 hashes to the URLs of your application's assets, so when they change, their URL changes.

v2.0.9(4y ago)0177MITPHPPHP &gt;=5.4.0

Since Aug 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ejunker/laravel-cachebuster)[ Packagist](https://packagist.org/packages/ejunker/laravel-cachebuster)[ Docs](http://github.com/TheMonkeys/laravel-cachebuster)[ RSS](/packages/ejunker-laravel-cachebuster/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (14)Used By (0)

[![The Monkeys](https://camo.githubusercontent.com/580df7170b07322a64b603ab110484f004b2464ccf1a56e9fc2b3dad16b39378/687474703a2f2f7777772e7468656d6f6e6b6579732e636f6d2e61752f696d672f6d6f6e6b65795f6c6f676f2e706e67)](https://camo.githubusercontent.com/580df7170b07322a64b603ab110484f004b2464ccf1a56e9fc2b3dad16b39378/687474703a2f2f7777772e7468656d6f6e6b6579732e636f6d2e61752f696d672f6d6f6e6b65795f6c6f676f2e706e67)

Laravel Cachebuster
===================

[](#laravel-cachebuster)

Adds MD5 hashes to the URLs of your application's assets, so when they change, their URL changes. URLs contained in your css files are transformed automatically; other URLs (such as those referenced via ``, `` and `` tags) are easy to transform too via a helper function in your blade templates.

Also supports adding a CDN proxy prefix to your asset URLs, to quickly and easily add the performance and scalability of a transparent CDN such as [Cloudfront](http://aws.amazon.com/cloudfront/) to your app.

Installation
------------

[](#installation)

To get the version of cachebuster compatible with your version of laravel, follow the notes below regarding installation

1. Add the following to your **composer.json**

#### For Laravel 5.x and Laravel 6

[](#for-laravel-5x-and-laravel-6)

```
"themonkeys/cachebuster" :"2.*"
```

#### For Laravel 4.x

[](#for-laravel-4x)

```
"themonkeys/cachebuster" :"1.*"
```

> **Note:** IFor continued Laravel 4 support, please use the cachebuster 1.x releases, and not dev-master\*

2. Run `composer update`
3. Once cachebuster is installed you need to register the service provider with the application. Open up `app/config/app.php` and find the `providers` key.

```
'providers' => array(
    'Themonkeys\Cachebuster\CachebusterServiceProvider',
)
```

4. The package ships with a facade which provides a concise static syntax for encoding your URLs. You can register the facade via the `aliases` key of your `app/config/app.php` file.

```
'aliases' => array(
    'Bust' => 'Themonkeys\Cachebuster\Cachebuster'
)
```

5. Add the following to your .htaccess file **before** the Laravel rewrite rule:

```
# ------------------------------------------------------------------------------
# | Remove cachebuster hash from request URLs if present                       |
# ------------------------------------------------------------------------------

    RewriteRule ^(.*)-[0-9a-f]{32}(\.(.*))$ $1$2 [DPI]

```

> **Note:** If you're using NGINX and not interpreting `.htaccess` files, see [this gist](https://gist.github.com/RTC1/89d7f95555be8cf7d1aa) by @RTC1 for the equivalent NGINX rewrite rule.

And add the following to your .htaccess file **after** the Laravel rewrite rule:

```
# ------------------------------------------------------------------------------
# | Allow Laravel to pre-process the css to add cachebusters to image urls     |
# ------------------------------------------------------------------------------

    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule ^(.*\.css)$ index.php [L]

```

6. Finally, add this to your `app/routes.php` file:

```
Route::get('{path}', function($filename) {
  return Bust::css($filename);
})->where('path', '.*\.css$');
App::make('cachebuster.StripSessionCookiesFilter')->addPattern('|\.css$|');
```

> Note: this wildcard route is known to conflict with the wildcard route used by [croppa](https://github.com/BKWLD/croppa), rendering Croppa ineffective. Should that affect you, simply be more specific with the CSS route. For example, if all your css files are in a `css/` folder:
>
> ```
> Route::get('/css/{path}', function($filename) {
>     return Bust::css("/css/$filename");
> })->where('path', '.*\.css$');
>
> ```
>
>
>
> Or you could even use `Bust::css()` within a filter instead.

Configuration
-------------

[](#configuration)

To configure the package, you can use the following command which wil publish the configuration file(s) to `app/config/`.

#### Laravel 5.x

[](#laravel-5x)

```
php artisan vendor:publish
```

Will publish to: `/app/config/cachebuster.php`.

The settings themselves are documented inside `/app/config/cachebuster.php`. You can change the default settings here too, for when the environment variables are not detected.

> **Note:** Laravel 5.x [changed envronment configuration to use dotEnv files](http://laravel.com/docs/5.0/configuration#environment-configuration "Laravel 5"), and you will need to "enable" cachebuster using the dotEnv paradigm for each environment your application requires.

For example, to enable cachebuster, open up your `.env` file, and add the following line

```
CACHEBUSTER_ENABLED = true
```

#### Laravel 4.x

[](#laravel-4x)

```
php artisan config:publish themonkeys/cachebuster
```

Will publish to: `app/config/packages/themonkeys/cachebuster`.

Or you can just create a new file in that folder and only override the settings you need. The settings themselves are documented inside `app/config/packages/themonkeys/cachebuster/config.php`.

Using Laravel's built-in development server
-------------------------------------------

[](#using-laravels-built-in-development-server)

You may want to use Laravel's built-in development server to serve your application, for example for automated testing. Since that server doesn't support the necessary URL rewriting, the simplest solution is to disable cachebusting for that environment. Do that by creating the file `app/config/packages/themonkeys/cachebuster/testing/config.php` (replace `testing` with the environment used by the development server) with the contents:

```
