diff options
| author | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
|---|---|---|
| committer | sillylaird <sillyfanboy@gmail.com> | 2026-09-03 00:33:59 +0000 |
| commit | 898b52edcb47bcb3e9d6106e74ca73e74ea01e70 (patch) | |
| tree | 85c6ee5ad58b860144551184d4cf86b560c62b91 /partials/asset_version.php | |
| download | www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.tar.gz www-898b52edcb47bcb3e9d6106e74ca73e74ea01e70.zip | |
Diffstat (limited to 'partials/asset_version.php')
| -rw-r--r-- | partials/asset_version.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/partials/asset_version.php b/partials/asset_version.php new file mode 100644 index 0000000..ff5204f --- /dev/null +++ b/partials/asset_version.php @@ -0,0 +1,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) : ''); + } +} |
