paulbunyannet / autoversion
Auto versioning class for front end assets.
Installs: 25 052
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-11-23 02:52:12 UTC
README
#paulbunyannet/autoversion
paulbunyannet/autoversion Cache busting mechanisim for front end assets, used with the cache busting mechanism provided by the HTML5 Boilerplate Apache .htaccess configuration.
Installation
In your terminal, just run:
composer require "paulbunyannet/autoversion":"~1.0"
Configuration
This package is framework agnostic, the configuration process is:
// Auto-load composer packages use Pbc\AutoVersion\AutoVersion; require 'vendor/autoload.php'; // Create new AutoVersion object and configure the document root $auto = new AutoVersion($_SERVER['DOCUMENT_ROOT']);
Add to your .htaccess file, before any other routing mod rewrites
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(bmp|css|cur|gif|ico|jpe?g|js|png|svgz?|webp|webmanifest)$ $1.$3 [L]
</IfModule>
Usage
In your views, just call:
// $pathToAsset is relative to the document root configured above, $auto->file($pathToAsset);
for example:
<link rel="stylesheet" href="<?=$auto->file('/css/main.css') ?>"> <script src="<?=$auto->file('/js/main.js') ?>"></script>
which will output file names with their modified time appended to file name:
<link rel="stylesheet" href="/css/main.1234567890.css">
<script src="/js/main.1234567890.js"></script>