WebsiteBaker Support (2.13.x) > General Help & Support

Versioned css and js for modules and standard files

(1/1)

CodeALot:
For my templates, I have made a function that will always look for modified CSS-files so the visitor will always be 'forced' to load the latest version:


--- Code: ---function css_versioned($filename) {
    $base_path = '/templates/main/css/';
    $filepath  = $_SERVER['DOCUMENT_ROOT'] . $base_path . $filename;
    return file_exists($filepath)
        ? $base_path . $filename . '?v=' . filemtime($filepath)
        : $base_path . $filename;
}

--- End code ---

The CSS files in that directory will then be called like for example:

--- Code: ---<link rel="stylesheet" href="<?php echo css_versioned(&#39;basics.css&#39;); ?>" media="all" />
--- End code ---

It would be nice if WB did that by default for any CSS and JS file it has to load, thus bypassing stubborn caches on the visitor's devices.

sternchen8875:
aus meiner Sicht eine gute Idee und längst Standard in den meisten CMS. Für WebsiteBaker wird die Integration allerdings etwas umfangreicher, muß man doch die ganzen Funktionen mit einbeziehen, z.b. register_modfiles.. ..

In my opinion, this is a good idea and has long been standard in most CMSs. However, for WebsiteBaker, the integration becomes a bit more complex, as you have to include all the functions, e.g., register_modfiles.. ..

Navigation

[0] Message Index

Go to full version