Skip to content
File Method and css/js helper to add hash to files
Branch: master
Clone or download
bnomei @bvdputte’s fingerprint plugin
Signed-off-by: Bruno Meilick <b@bnomei.com>
Latest commit 9855247 Mar 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
classes
vendor pluginkit Feb 6, 2019
.editorconfig pluginkit Feb 6, 2019
.gitignore pluginkit Feb 6, 2019
.php_cs.dist kirby3 rc-2 Dec 22, 2018
composer.json removed localhost/webpack checks, debugforce config-setting Feb 6, 2019
composer.lock removed localhost/webpack checks, debugforce config-setting Feb 6, 2019
index.php removed localhost/webpack checks, debugforce config-setting Feb 6, 2019
readme.md

readme.md

Kirby 3 Fingerprint

GitHub release License Kirby Version Kirby 3 Pluginkit

File Method and css/js helper to add cachbusting hash and optional Subresource Integrity to files.

Commerical Usage

This plugin is free but if you use it in a commercial project please consider to

Installation

  • unzip master.zip as folder site/plugins/kirby3-fingerprint or
  • git submodule add https://github.com/bnomei/kirby3-fingerprint.git site/plugins/kirby3-fingerprint or
  • composer require bnomei/kirby3-fingerprint

Performance

Hash and SRI values are cached and only updated when original file is modified.

Usage

echo Bnomei\Fingerprint::css('/assets/css/index.css');
// https://../assets/css/index.css?v=1203291283

echo Bnomei\Fingerprint::js('/assets/js/index.min.js');
// https://../assets/js/index.min.js?v=1203291283

echo $page->file('ukulele.pdf')->fingerprint();
// https://../ukulele.pdf?v=1203291283

echo $page->file('ukulele.pdf')->integrity();
// sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC

// generate sri from local file
echo Bnomei\Fingerprint::js(
    '/assets/js/index.min.js', 
    [
        "integrity" => true
    ]
); 
/*
<script src="https://../assets/js/index.min.js"
    integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
    crossorigin="anonymous"></script>
*/

echo Bnomei\Fingerprint::js(
    'https://external.cdn/framework.min.js', 
    [
        "integrity" => "sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
    ]
);
/*
<script src="https://external.cdn/framework.min.js"
    integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
    crossorigin="anonymous"></script>
*/

Settings

debugforce

  • default: true will flush cache if debug mode is active

hash

  • default: will lead to query string and does not require htaccess setup. thanks @fabianmichael. #1

integrity

  • to disable sri set option 'integrity' => null,

ssl

  • default: false. boolean value or callback to force https scheme.

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.

License

MIT

It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.

Similar Plugins

  • consider kirby-fingerprint if you do not want a querystring (myfile.js?v=1928356) but an filename rewrite rule using htaccess (myfile.1928356.js) and you do not want to override the bnomei.fingerprint.hash option like described here.

Credits

You can’t perform that action at this time.