PHPackages                             monolyth/cachet - 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. monolyth/cachet

ActiveLibrary

monolyth/cachet
===============

Cachebuster command

1.0.5(5y ago)0138[2 PRs](https://github.com/monolyth-php/cachet/pulls)1MITPHP

Since Sep 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/monolyth-php/cachet)[ Packagist](https://packagist.org/packages/monolyth/cachet)[ RSS](/packages/monolyth-cachet/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (10)Used By (1)

monolyth/cachet
===============

[](#monolythcachet)

Cachebuster command

When serving static assets (mainly JavaScript and CSS, but perhaps also images...) sometimes you'll want to "bust" the browser cache to make sure visitors receive the correct version. This is what `cachet` aims to help in.

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

[](#installation)

Composer (recommended):

```
$ composer require monolyth/cachet
```

Usage
-----

[](#usage)

`cachet` depends on a global "versions file" where all current versions are stored. This should contain a JSON hash of all files/hashes (relative to your projet's root directory). Initially you can fill it with empty strings as the hashes; on first run, the actual hashes will be replaced:

```
{"some/file/somewhere.js":""}
```

Whenever you run the `cachet` CLI command, the current hashes will be inserted or updated (based on the files' contents):

```
$ vendor/bin/cliff cachet path/to/versions.json public/folder
```

The command also creates symlinks with the correct hash inserted into the public folder, e.g. `test.js` might become `test.abcdabcd.js`. You should refer to these linked files in your frontend code, as the hash will change when the file contents have changed.

Note that both arguments are relative to the current working directory.

Injecting version numbers in templates
--------------------------------------

[](#injecting-version-numbers-in-templates)

Monolyth projects usually use Twig, so we've included a `TwigFunction` `cachet`to easily inject the correct version numbers.

Somewhere in a central place in your application, inject it using your `Twig\Enviroment` of choice:

```
