PHPackages                             weareferal/asset-versioner - 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. weareferal/asset-versioner

ActiveCraft-plugin

weareferal/asset-versioner
==========================

Automatically create cache-busting versions of all your assets

v1.0.8(6y ago)41731[2 issues](https://github.com/weareferal/craft-asset-versioner/issues)proprietaryPHPCI failing

Since Jan 18Pushed 6y ago2 watchersCompare

[ Source](https://github.com/weareferal/craft-asset-versioner)[ Packagist](https://packagist.org/packages/weareferal/asset-versioner)[ RSS](/packages/weareferal-asset-versioner/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (1)Versions (12)Used By (0)

Asset Versioner
===============

[](#asset-versioner)

[![](src/icon.svg)](src/icon.svg)

Automatically generate unique hashed versions of static files and assets for efficient and reliable browser caching.

Overview
--------

[](#overview)

[![Screenshot overview](resources/img/screenshot-1.jpg)](resources/img/screenshot-1.jpg)

This plugin automatically generates cache-busting hashed versions for both the static files within your webroot (JS, CSS, fonts etc.) as well as uploaded volume assets.

Unlike other approaches, this means you don't have to handle anything as part of your development workflow (for example, using Gulp to create the hashed files, or maintaining a manifest file).

For static files, it does this by creating a `scan` command that you can run on every deployment:

```
./craft asset-versioner/scan
```

This command searches for static files within your webroot and creates hashed versions alongside. It then saves the reference in a keystore that is accessed via a twig template filter:

```

```

For asset files, the versioning happens automatically when a new file is uploaded, meaning you don't have to do anything at all to get versioning for free.

Background
----------

[](#background)

"Versioning" your files is a great way to avoid having caching issues when serving your site. Without it it's possible that visitors to your site may see old out-of-date versions of your files (CSS, JS etc.) that have come from their browser cache.

Usually versioning is simply the process of appending a md5 hash of a file to the end of its filename:

> /js/scripts.min.js &gt; /js/scripts.min.93477db0cd0ca27669fac6e6aac05c8b.js

With this approach, there's no way of ever being served an out-of-date version of the file, as its content is reflected in the md5 hash within the filename itself.

There are numerous existing approach to creating unique "versioned" files, but they largely involve handling the versioning yourself within your front-end JavaScript build pipeline. This is error prone and requires oversight. Furthermore this only handles your static files, not your uploaded Craft *asset* files.

Asset Versioner aims to handle both of these cicumstances automatically.

Requirements
------------

[](#requirements)

This plugin requires Craft CMS 3.0.0 or later.

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

[](#installation)

To install the plugin, follow these instructions.

1. Open your terminal and go to your Craft project:

    ```
    $ cd /path/to/project
    ```
2. Then tell Composer to load the plugin:

    ```
    $ composer require weareferal/asset-versioner
    ```
3. In the Control Panel, go to Settings → Plugins and click the *Install* button for Asset Versioner.

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

[](#configuration)

Configuration is handled solely via a `config/asset-versioner.php` file (there is no settings page). This is because asset versioning is almost always something you only want to do on your *production* instance and not on development or staging.

By default, all asset versioning is disabled, so you need to enable it for the environments you are interested in.

You can copy the `config.php` example from the repo. Here is an example:

```
