WebsiteBaker Community Forum
WebsiteBaker Support (2.13.x) => General Help & Support => Topic started by: CodeALot on January 31, 2025, 05:41:34 PM
-
When I was working on a website and changed the look of a few modules in their frontend.css files, I got a reaction from the client that "he didn't see the change". This because his browser cache still used the old stylesheets.
There is a way to force a browser to load the new CSS file, by adding a version number to the css call. Like frontend.css?v3
So I changed frontend.functions.php in /framework, the function preparelink into this:
case 'css':
$sRetval .= "\t\t".'<link rel="stylesheet" href="'.$oReg->AppUrl.''.$sLinks.'?[[CSSVERSION]]" media="screen">'."\n";
break;
Then I made droplet CSSVERSION that reads:
$version="v4";
return $version;
Every time I now make changes to frontend.css of ANY module, all I need to do is change the version number in the droplet, and visitors will be served the latest CSS files.
-
I know it. "Can not see changes, looks like before" ;D
Before years Stefek had a solution for the style.css.
index.php of the template in <head> area
// function fresh_file()
function fresh_file($file){
$used_file = TEMPLATE_DIR.'/'.$file;
$fresh_used_file = WB_PATH.'/templates/'.TEMPLATE.'/'.$file;
echo $used_file.'?'.filemtime ($fresh_used_file);
}
use it:
<link rel="stylesheet" href="<?php fresh_file('style.css');?>" media="screen,projection" />
works automatically.
-
That's an option too, but that forces a new download even if the file has not changed because the browser sees a different timestamp on every pageload.
I think my solution may be a bit more work, but scores better in terms of server load and loading times ;-)
Also, this only works nicely for your template CSS files. Not for all the frontend.css files that your site uses for every single module.
I think "my way" is better :-D
-
filemtime changed only if the file was modified. ;)
-
Ah, I overlooked that :-)
Still, the module frontend.css argument stands :-)
-
Ok. I never thought of filemtime :-) (Thanks dbs :-)
So I put 2 and 2 together and now frontend.functions. php has this snippet:
case 'css':
$sRetval .= "\t\t".'<link rel="stylesheet" href="'.$oReg->AppUrl.''.$sLinks.'?'.filemtime($sLinks).'" media="screen">'."\n";
break;
forcing the visitor's browser to always read the latest CSS-version of any frontend.css.
-
Simple Question: Why is this not the standard in WebsiteBaker?
we found this solution everywhere in the web, its part of the description on php.net, but why is it not part of our code? :roll:
-
Simple Question: Why is this not the standard in WebsiteBaker?
we found this solution everywhere in the web, its part of the description on php.net, but why is it not part of our code? :roll:
Well... Maybe next version? :-)