<commit_before>[![Build Status](https://travis-ci.org/spekkionu/laravel-assetcachebuster.png?branch=master)](https://travis-ci.org/spekkionu/laravel-assetcachebuster)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/spekkionu/laravel-assetcachebuster/badges/quality-score.png?s=3f8e68ec5a903cbe6934fe6acfc40c0a751ec3f6)](https://scrutinizer-ci.com/g/spekkionu/laravel-assetcachebuster/)
[![Code Coverage](https://scrutinizer-ci.com/g/spekkionu/laravel-assetcachebuster/badges/coverage.png?s=6466dda4d16f042564234456347581aca7cae9dc)](https://scrutinizer-ci.com/g/spekkionu/laravel-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
============

Add `spekkionu\assetcachebuster` as a requirement to composer.json:

```javascript
{
    "require": {
        "spekkionu/assetcachebuster": "dev-master"
    }
}
```

Update your packages with `composer update` or install with `composer install`.

Once Composer has installed or updated your packages you need to register the service provider with the application.
Open up `app/config/app.php` and find the `providers` key.

```php
'providers' => array(
    'Spekkionu\Assetcachebuster\AssetcachebusterServiceProvider',
)
```

In order to generate an asset url the asset url generation facade must be registered.
You can register the facade via the `aliases` key of your `app/config/app.php` file.

```php
'aliases' => array(
    'Asset' => 'Spekkionu\Assetcachebuster\Facades\Cachebuster'
)
```

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:

```ApacheConf
# ------------------------------------------------------------------------------
# | Filename-based cache busting                                               |
# ------------------------------------------------------------------------------

# Rewrite assets/hash/file.js to assets/file.js
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove prefix from asset files
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^[a-f0-9]{32}/(.*)$ $1 [L]

</IfModule><commit_msg>Update README.MD to include Nginx rules<commit_after>[![Build Status](https://travis-ci.org/spekkionu/laravel-assetcachebuster.png?branch=master)](https://travis-ci.org/spekkionu/laravel-assetcachebuster)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/spekkionu/laravel-assetcachebuster/badges/quality-score.png?s=3f8e68ec5a903cbe6934fe6acfc40c0a751ec3f6)](https://scrutinizer-ci.com/g/spekkionu/laravel-assetcachebuster/)
[![Code Coverage](https://scrutinizer-ci.com/g/spekkionu/laravel-assetcachebuster/badges/coverage.png?s=6466dda4d16f042564234456347581aca7cae9dc)](https://scrutinizer-ci.com/g/spekkionu/laravel-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
============

Add `spekkionu\assetcachebuster` as a requirement to composer.json:

```javascript
{
    "require": {
        "spekkionu/assetcachebuster": "dev-master"
    }
}
```

Update your packages with `composer update` or install with `composer install`.

Once Composer has installed or updated your packages you need to register the service provider with the application.
Open up `app/config/app.php` and find the `providers` key.

```php
'providers' => array(
    'Spekkionu\Assetcachebuster\AssetcachebusterServiceProvider',
)
```

In order to generate an asset url the asset url generation facade must be registered.
You can register the facade via the `aliases` key of your `app/config/app.php` file.

```php
'aliases' => array(
    'Asset' => 'Spekkionu\Assetcachebuster\Facades\Cachebuster'
)
```

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:

```ApacheConf
# ------------------------------------------------------------------------------
# | Filename-based cache busting                                               |
# ------------------------------------------------------------------------------

# Rewrite assets/hash/file.js to assets/file.js
<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove prefix from asset files
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^[a-f0-9]{32}/(.*)$ $1 [L]

</IfModule>
```

For Nginx, add the following to your virtual host file

```Nginx
# ------------------------------------------------------------------------------
# | Filename-based cache busting                                               |
# ------------------------------------------------------------------------------
# Rewrite assets/hash/file.js to assets/file.js
    location ~* "^\/[a-f0-9]{32}(\/*\.*(.*))$" {
        try_files $uri $1;
    }
{'fraction_non_alphanumeric': 0.18033886931722864, 'fraction_numerical': 0.01895655091427613, 'mean_word_length': 2.839021249195106, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6899416', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1700, 'n_words': 531}