Skip to content

Commit a255e5e

Browse files
committed
query string as default instead of htaccess filemtime
Signed-off-by: Bruno Meilick <[email protected]>
1 parent 625fc85 commit a255e5e

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

classes/fingerprint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ static private function isLocalhost() {
2323
return in_array( $_SERVER['REMOTE_ADDR'], array( '127.0.0.1', '::1' ));
2424
}
2525

26-
static private function fingerprint($file) {
26+
static private function fingerprint($file, $extension) {
2727
$callback = option('bnomei.fingerprint.hash', null);
2828

2929
if($callback && is_callable($callback)) {
30-
return call_user_func_array($callback, [$file]);
30+
return call_user_func_array($callback, [$file, $extension]);
3131
}
3232

33-
return \filemtime($file);
33+
return \filemtime($file) . '.' . $extension;
3434
}
3535

3636
static public function injectFileMTime($url) {
@@ -40,7 +40,7 @@ static public function injectFileMTime($url) {
4040
\Kirby\CMS\App::instance()->roots()->index() . DIRECTORY_SEPARATOR . ltrim($url, '/');
4141

4242
if(\F::exists($file)) {
43-
$filename = \F::name($file) . '.' . static::fingerprint($file) . '.' . \F::extension($file);
43+
$filename = \F::name($file) . '.' . static::fingerprint($file, \F::extension($file));
4444
$dirname = \dirname($file);
4545
$url = ($dirname === '.') ? $filename : ($dirname . '/' . $filename);
4646
}

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bnomei/kirby3-fingerprint",
33
"type": "plugin",
4-
"version": "1.1.2",
4+
"version": "1.2.0",
55
"license": "MIT",
66
"autoload": {
77
"files": [
@@ -25,5 +25,6 @@
2525
],
2626
"require": {
2727
"getkirby/cms": "3.0.*"
28-
}
28+
},
29+
"minimum-stability": "beta"
2930
}

config.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
Kirby::plugin('bnomei/fingerprint', [
44
'options' => [
5-
'hash' => null, // defaults to: function ($file) { return \filemtime($file); }
5+
'hash' => function ($file, $extension) {
6+
return $extension . '?v=' . \filemtime($file);
7+
}
68
],
79
'fileMethods' => [
810
'fingerprint' => function ($file) {

readme.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ echo Bnomei\Fingerprint::js('/assets/js/index.min.js');
1212
echo $page->image('ukulele.jpg')->fingerprint();
1313
```
1414

15-
## Setup
15+
## Settings
16+
17+
**hash**
18+
default: will lead to query string and does not require htaccess setup. thanks @fabianmichael. [#1](https://github.com/bnomei/kirby3-fingerprint/issues/1)
19+
20+
## Setup for filemtime()
1621

1722
Add the following lines to your htaccess file (after RewriteBase) unless you use a different hash function (see settings):
1823

@@ -31,14 +36,6 @@ location /assets {
3136
}
3237
```
3338

34-
## Settings
35-
36-
**hash**
37-
_default: null_
38-
which yields `function ($file) { return \filemtime($file); }`.
39-
40-
> NOTE: config settings do not override plugin settings (yet). issue pending.
41-
4239
## TODO
4340

4441
- hijack `css` and `js` and their auto variant helpers

0 commit comments

Comments
 (0)