From c897aa84567ba046644a87e23b32f3df4c5845d3 Mon Sep 17 00:00:00 2001 From: Joakim Reinert Date: Mon, 4 May 2015 00:58:50 +0200 Subject: Set cache buster for js with urlArgs setting No more need for timestamp in filename of minified main js --- .gitignore | 2 +- application/helpers/filebin_helper.php | 7 +++---- application/views/header.php | 3 ++- scripts/optimize_js.sh | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c64e87ede..9c3bc7e61 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ application/logs/* !application/logs/index.html !application/logs/.htaccess -data/js/main.min.*.js +data/js/main.min.js diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 8db605cfd..7adab7279 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -135,11 +135,10 @@ function link_with_mtime($file) return $link; } -function main_min_js_name() +function js_cache_buster() { - $files = glob(FCPATH . 'data/js/main.min.*.js'); - $filename = basename(empty($files) ? 'MAIN_NOT_MINIFIED' : end($files)); - return str_replace('.js', '', $filename); + $minified_main = FCPATH.'/data/js/main.min.js'; + return file_exists($minified_main) ? filemtime($minified_main) : time(); } function handle_etag($etag) diff --git a/application/views/header.php b/application/views/header.php index f80ffed05..6e7ef3a92 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -32,8 +32,9 @@ if (is_cli_client() && !isset($force_full_html)) { window.appConfig = {}; require.config({ baseUrl: '/data/js', + urlArgs: '', paths: { - 'main': ['', 'main'] + 'main': ['main.min', 'main'] } }); require(['main']); diff --git a/scripts/optimize_js.sh b/scripts/optimize_js.sh index 82e9a25e6..f1bc1126e 100755 --- a/scripts/optimize_js.sh +++ b/scripts/optimize_js.sh @@ -2,5 +2,5 @@ script_dir=$(dirname "$0") js_dir="$script_dir/../data/js" -outfile="$js_dir/main.min.$(date +%s).js" +outfile="$js_dir/main.min.js" node "$script_dir/r.js" -o mainConfigFile="$js_dir/main.js" name=main out=$outfile -- cgit v1.2.3-24-g4f1b