From 3bc482adf49176ee83fde295428d10804336f1a9 Mon Sep 17 00:00:00 2001 From: alext Date: Wed, 8 Nov 2017 15:22:30 +0100 Subject: [PATCH] Added asset_helper file and cache busting token config. --- src/application/config/config.php | 12 ++++++++++ src/application/helpers/asset_helper.php | 29 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/application/helpers/asset_helper.php diff --git a/src/application/config/config.php b/src/application/config/config.php index 51becf70..31bc13d7 100644 --- a/src/application/config/config.php +++ b/src/application/config/config.php @@ -262,6 +262,18 @@ $config['log_date_format'] = 'Y-m-d H:i:s'; */ $config['cache_path'] = __DIR__ . '/../../storage/cache/'; +/* +|-------------------------------------------------------------------------- +| Cache Busting Token +|-------------------------------------------------------------------------- +| +| This token will be appending to asset URLs in order to invalidate the browser +| cache and enforce end clients to fetch new files. Update the token with each +| new release. +| +*/ +$config['cache_busting_token'] = 'dfsg8s09df8g098'; + /* |-------------------------------------------------------------------------- | Encryption Key diff --git a/src/application/helpers/asset_helper.php b/src/application/helpers/asset_helper.php new file mode 100644 index 00000000..fee0378b --- /dev/null +++ b/src/application/helpers/asset_helper.php @@ -0,0 +1,29 @@ + + * @copyright Copyright (c) 2013 - 2017, Alex Tselegidis + * @license http://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link http://easyappointments.org + * @since v1.3.0 + * ---------------------------------------------------------------------------- */ + +/** + * Assets URL helper function. + * + * This function will create an asset file URL that includes a cache busting parameter in order + * to invalidate the browser cache in case of an update. + * + * @param string $uri Relative URI (just like the one used in the base_url helper). + * @param string|null $protocol Valid URI protocol. + * + * @return string Returns the final asset URL. + */ +function asset_url($uri = '', $protocol = NULL) { + $ci =& get_instance(); + + return base_url($uri . '?' . $ci->config->item('cache_busting_token'), $protocol); +}