WebsiteBaker Community Forum

WebsiteBaker Support (2.13.x) => General Help & Support => Topic started by: CodeALot on September 29, 2025, 12:49:22 AM

Title: Versioned css and js for modules and standard files
Post by: CodeALot on September 29, 2025, 12:49:22 AM
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: [Select]
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;
}

The CSS files in that directory will then be called like for example:
Code: [Select]
<link rel="stylesheet" href="<?php echo css_versioned(&#39;basics.css&#39;); ?>" media="all" />
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.
Title: Re: Versioned css and js for modules and standard files
Post by: sternchen8875 on September 29, 2025, 12:14:31 PM
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.. ..