php - Easy method of including a timestamp (mtime) style/js versioning? -
in kohana, there quick , easy way use html::style() helper automatically include unix timestamp mtime of file after css or js file name in case of script?
in cakephp, use html/css helper , in configuration:
configure::write('asset.timestamp', 'force');
this way when doing following:
echo $this->html->css('styles');
it output:
<link rel="stylesheet" type="text/css" href="/css/styles.css?1338350352" />
i use in every project:
class html extends kohana_html { /** * given file, i.e. /css/base.css, replaces string containing * file's mtime, i.e. /css/base.1221534296.css. * * @param $file file loaded. must absolute path (i.e. * starting slash). */ public static function auto_version($file) { if (!file_exists($_server['document_root'] . '/' . $file)) return $file; $mtime = filemtime($_server['document_root'] . '/' . $file); return preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", $file); } }
in template view:
<link type="text/css" href="<?php echo html::auto_version('/media/css/global.css') ?>" rel="stylesheet" />
credits go kip answer how force browser reload cached css/js files?
ps. remember add below rule .htaccess:
rewriterule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [l]
Comments
Post a Comment