CMS MADE SIMPLE FORGE

CMS Made Simple Core

 

[#7566] Include user agent name and version in cached css filename

avatar
Created By: Georg Busch (nan)
Date Submitted: 2012-02-06 14:43

Assigned To:
Resolution: Won't Fix
State: Closed
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.

History

Comments
avatar
Date: 2012-02-07 09:50
Posted By: Robert Campbell (calguy1000)

jut put the logic into your page template and call different stylesheets.
      
Updates

Updated: 2014-03-14 23:30
state: Open => Closed

Updated: 2012-02-07 09:50
resolution_id: => 8