From 7f51a795a50a0202c22531e06290b6ffc9526de4 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 15 Aug 2026 09:00:40 +0000 Subject: [PATCH] Cache-bust local css/js so a deploy is picked up immediately Apache serves this site's static files with only Last-Modified/ETag and no Cache-Control or Expires, so browsers apply heuristic freshness and can hold a stale stylesheet for hours. Deploys here are a file copy, so nothing else signals a change. During development this masked CSS edits three separate times; on the live site a returning customer would keep the old stylesheet after a deploy with no way to know. Adds asset_ver() (autoloaded), which returns the asset URL with the file's mtime appended, so the URL itself changes whenever the file does. Falls back to the plain URL when the file is missing, so a bad path degrades to the previous behaviour rather than warning. All 54 local css/js links now route through it, across the four *-head.php and four *-skeleton-bottom.php includes. Notes - Remote assets are deliberately untouched: Google Fonts, momentjs, cookieyes and the googleapis jQuery keep their own URLs. Only files inside the webroot are versioned. - vertical-head.php has one dynamic path (assets/css/) which is special-cased; a generic rewrite would swallow the nested --- application/config/autoload.php | 2 +- application/helpers/asset_helper.php | 47 +++++++++++++++++++ application/views/includes/barber-head.php | 16 +++---- .../views/includes/barber-skeleton-bottom.php | 10 ++-- application/views/includes/beauty-head.php | 16 +++---- .../views/includes/beauty-skeleton-bottom.php | 10 ++-- application/views/includes/head.php | 18 +++---- .../views/includes/main-skeleton-bottom.php | 12 ++--- application/views/includes/vertical-head.php | 16 +++---- .../includes/vertical-skeleton-bottom.php | 10 ++-- 10 files changed, 102 insertions(+), 55 deletions(-) create mode 100644 application/helpers/asset_helper.php diff --git a/application/config/autoload.php b/application/config/autoload.php index 0da0117..12e19aa 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -89,7 +89,7 @@ $autoload['drivers'] = array(); | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('vertical'); +$autoload['helper'] = array('vertical', 'asset'); /* | ------------------------------------------------------------------- diff --git a/application/helpers/asset_helper.php b/application/helpers/asset_helper.php new file mode 100644 index 0000000..25b293f --- /dev/null +++ b/application/helpers/asset_helper.php @@ -0,0 +1,47 @@ + appended. + * + * Only for files inside the webroot. Remote assets (Google Fonts, the + * cookieyes script, momentjs) must keep their own URLs untouched. + * + * Falls back to the plain URL when the file is missing, so a bad path + * degrades to the previous behaviour rather than emitting a warning. + * + * @param string $path webroot-relative, e.g. 'assets/css/main.css' + * @return string + */ + function asset_ver($path) + { + $path = ltrim((string) $path, '/'); + $url = rtrim(SITEURL, '/').'/'.$path; + + $file = FCPATH.$path; + + if ($path !== '' && is_file($file)) + { + $url .= (strpos($url, '?') === FALSE ? '?' : '&').'v='.filemtime($file); + } + + return $url; + } +} diff --git a/application/views/includes/barber-head.php b/application/views/includes/barber-head.php index 2ed6678..336088d 100755 --- a/application/views/includes/barber-head.php +++ b/application/views/includes/barber-head.php @@ -32,17 +32,17 @@ $this->load->helper('url'); - - + + - - - + + + - - - + + + \ No newline at end of file diff --git a/application/views/includes/barber-skeleton-bottom.php b/application/views/includes/barber-skeleton-bottom.php index 4c823f1..b51897c 100755 --- a/application/views/includes/barber-skeleton-bottom.php +++ b/application/views/includes/barber-skeleton-bottom.php @@ -5,10 +5,10 @@ - - - - - + + + + + diff --git a/application/views/includes/beauty-head.php b/application/views/includes/beauty-head.php index 4a1920e..8745c16 100755 --- a/application/views/includes/beauty-head.php +++ b/application/views/includes/beauty-head.php @@ -31,20 +31,20 @@ $this->load->helper('url'); - + - - + + - - + + - - - + + + - - - - + + + + + diff --git a/application/views/includes/head.php b/application/views/includes/head.php index 1af4b14..104faf5 100755 --- a/application/views/includes/head.php +++ b/application/views/includes/head.php @@ -31,21 +31,21 @@ $this->load->helper('url'); - - + + - + - + - - - - - + + + + + - - - - - + + + + + + diff --git a/application/views/includes/vertical-head.php b/application/views/includes/vertical-head.php index 665db75..b8c6ac9 100644 --- a/application/views/includes/vertical-head.php +++ b/application/views/includes/vertical-head.php @@ -34,17 +34,17 @@ $this->load->helper('url'); - + - - + + - - + + - - - + + + diff --git a/application/views/includes/vertical-skeleton-bottom.php b/application/views/includes/vertical-skeleton-bottom.php index 1472753..3b33c40 100644 --- a/application/views/includes/vertical-skeleton-bottom.php +++ b/application/views/includes/vertical-skeleton-bottom.php @@ -6,10 +6,10 @@ - - - - - + + + + +