Summary:
Include user agent name and version in cached css filename
Detailed Description:
Since the stylesheets are cached entirely with one unique filename you cannot
filter some styles in the css for certain browsers using smarty tags. because if
the first user visits your page e.g. with FF10 and the 2nd user with IE 8 you
will get the cached css (wich was cached with FF10 optimized code).
It could be useful if each browser could get its own cached stylesheet.
Name and Version should be ok (full user agent would be overkill).
I use this code snippet to get the user agents name and version at the top of
function.stylesheet.php:
$browsers = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
'konqueror', 'gecko');
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ?
strtolower($_SERVER['HTTP_USER_AGENT']) : false;
$pattern = '#(?<browser>' . join('|', $browsers) . ')[/
]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
$browser = '';
$version = 0;
if (preg_match_all($pattern, $user_agent, $matches))
{
$i = count($matches['browser']) - 1;
$r = array($matches['browser'][$i] => $matches['version'][$i]);
$browser = $matches['browser'][$i];
$version = str_replace(',','.',floatval($matches['version'][$i]));
}
and for the filename i just use:
$filename =
'stylesheet_combined_'.md5($template_id.$use_https.$modified_date.$fnsuffix.$browser.$version).'.css';
or
$filename =
'stylesheet_'.md5('single'.$one['css_id'].$use_https.strtotime($one['modified_date']).$fnsuffix.$browser.$version).'.css';
So you can deliver stylesheets that are optimized for the used useragent.