blob: ff5204f053da65fa0f0d603373430da83fd9836b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?php
// partials/asset_version.php — cache-bust helper for static assets.
//
// Usage:
// require_once __DIR__ . '/partials/asset_version.php'; // adjust path
// Then: htmlspecialchars(asset_v('assets/css/site.css'), ENT_QUOTES)
// inside an href/src attribute.
//
// Paths are relative to the site document root (parent of partials/).
if (!function_exists('asset_v')) {
function asset_v(string $rel): string {
static $root = null;
if ($root === null) {
$root = dirname(__DIR__);
}
$abs = $root . '/' . ltrim($rel, '/');
$mt = @filemtime($abs);
return $rel . ($mt ? ('?v=' . $mt) : '');
}
}
|