Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Get the latest js/css changes in the cache

edited March 2013 in How do I?
Sometimes I edit the javascript files in the libraries folder.
Usually your/your clients' browser cached the file so the changes won't just work out of the box there.

To prevent the browsers from this well performing behaviour change the following files:
  • libraries/general.functions.php:
    add this function after the docu comment
    function getTime($filePath) {
    $time = filemtime(ROOT . $filePath);
    $cTime = filectime(ROOT . $filePath);
    if ($cTime > $time) {
    $time = $cTime;

    $isDST = (date('I', $time) == 1);
    $systemDST = (date('I') == 1);
    $adjustment = 0;
    if(!$isDST && $systemDST) {
    $adjustment = 3600;
    } else if($isDST && !$systemDST) {
    $adjustment = -3600;
    return ($time + $adjustment);
  • index.php:
    change from: <script src="libraries/script.loader.php?load=init" type="text/javascript"></script>
    <script src="libraries/ajax.functions.js" type="text/javascript"></script>

    &lt;script src="libraries/script.loader.php?load=init&amp;<!--?php echo getTime('libraries/ajax.init.js'); ?-->" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script src="libraries/ajax.functions.js?<!--?php echo getTime('libraries/ajax.functions.js'); ?-->" type="text/javascript"&gt;&lt;/script&gt;

    If you have more javascript,css,... includes add '?' after the extension as shown above.
This will just load the new files in the cache if the file is modified instead of the performance killing appending of '?'.

The getTime() function uses both the filem(odified)time() and the filec(reation)time() stamp of the $filePath because on an Windows the modified time stamp will not update on copied files.

Edit: ROOT added
Sign In or Register to comment.