From 2937bf1a47778ad1b804fee65ff3c9fe5c35ab61 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 28 May 2015 15:04:12 +0200 Subject: JS: Use newest file time for cache buster Really no need to reload the files with each page load. Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 563364d32..c1f302da3 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -137,8 +137,26 @@ function link_with_mtime($file) function js_cache_buster() { - $minified_main = FCPATH.'/data/js/main.min.js'; - return file_exists($minified_main) ? filemtime($minified_main) : time(); + $jsdir = FCPATH.'/data/js'; + $minified_main = $jsdir.'/main.min.js'; + if (file_exists($minified_main)) { + return filemtime($minified_main); + } + + $ret = 0; + + $it = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($jsdir), RecursiveIteratorIterator::SELF_FIRST); + + foreach ($it as $file) { + $mtime = $file->getMTime(); + if ($file->isFile()) { + if ($mtime > $ret) { + $ret = $mtime; + } + } + } + return $ret; } function handle_etag($etag) -- cgit v1.2.3-24-g4f1b