CSS/JS file versioning

Permalink 1 user found helpful
Hi all,

Actually, css/js file added with addHeaderItem() method output their filename with an extra "v" parameter "?v=XXXXXXX".

We can believe that files have versioning check to prevent browser cache. But no!

This param is generated by md5(APP_VERSION . PASSWORD_SALT), so it assumes, this method is only used for core-css which stays the same until the version changes (makes the versioning quite useless e.g. for packages and blocks).

It could be great if Concrete5 can implement a filemtime checking.

Thank you :)

moosh

moosh
 
Job replied on at Permalink Reply
Job
Seconded.
Wildspark replied on at Permalink Reply
This post is a bit older now, but I implemented an override to do exactly this after not finding an answer. I'm sure my code can be refined, but here it is. I added this in /helpers/html.php:

<?php 
defined('C5_EXECUTE') or die("Access Denied.");
class HtmlHelper extends Concrete5_Helper_Html {
    public function css($file, $pkgHandle = null, $uniqueItemHandle = array(),$cbEnable = false) {
        //Get the css object output by the parent
        $css = parent::css($file, $pkgHandle, $uniqueItemHandle);
        //Add new cachebusting param
        if ($cbEnable) {
            $css->file = $this->bustCache($css->file);
        }
        return $css;
    }
    public function javascript($file, $pkgHandle = null, $uniqueItemHandle = array(),$cbEnable = false) {
        //Get the js object output by the parent
        $js = parent::javascript($file, $pkgHandle, $uniqueItemHandle);


To minimize processing of core files which do only change on new version, I added an option flag to enable this cache busting. If there is a file path error it will add a log entry and should use the default version. So far this seems to be working for me.