aboutsummaryrefslogtreecommitdiffstats
path: root/partials/asset_version.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--partials/asset_version.php21
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) : '');
+ }
+}