WebsiteBaker Support (2.13.x) > General Help & Support
TIP - How to force new stylesheets to website visitors
CodeALot:
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:
--- Code: --- case 'css':
$sRetval .= "\t\t".'<link rel="stylesheet" href="'.$oReg->AppUrl.''.$sLinks.'?[[CSSVERSION]]" media="screen">'."\n";
break;
--- End code ---
Then I made droplet CSSVERSION that reads:
--- Code: ---$version="v4";
return $version;
--- End code ---
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.
dbs:
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
--- Code: --- // 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);
}
--- End code ---
use it:
<link rel="stylesheet" href="<?php fresh_file('style.css');?>" media="screen,projection" />
works automatically.
CodeALot:
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
dbs:
filemtime changed only if the file was modified. ;)
CodeALot:
Ah, I overlooked that :-)
Still, the module frontend.css argument stands :-)
Navigation
[0] Message Index
[#] Next page
Go to full version