bsmooth Posted May 23, 2011 Share Posted May 23, 2011 I am running into a lot of browser cache issues with the global.css from customers who are not technical enough to use the F5 key.http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/I am wondering if someone with solid PHP skill can assist in implementing the above suggestions into /class/tools.php so the addCSS function can include the auto versioning of CSS files to prevent future browser caching.I think this is a nice feature to include in future releases, otherwise a CSS browser cache problem makes PrestaShop look broken when it is not.PrestaShop version 1.4.0.17 Link to comment Share on other sites More sharing options...
bsmooth Posted May 23, 2011 Author Share Posted May 23, 2011 /* rewrites url with timestamp */ public function autoVer($url){ $path = pathinfo($url); $ver = '.'.filemtime($_SERVER['DOCUMENT_ROOT'].$url).'.'; $verCSS = str_replace('.', $ver, $path['basename']); return $verCSS; I added this to the classes\Tools.php and was able to pass $verCSS value back to addCSS in the FrontController.php file.The FrontController.php file is updated to this starting at line 397: public function setMedia() { global $cookie; // Tools::addCSS(_THEME_CSS_DIR_.'global.css', 'all'); $verCSS = Tools::autoVer(_THEME_CSS_DIR_.'global.css'); Tools::addCSS(_THEME_CSS_DIR_ . $verCSS, 'all'); After this, the HTML source code is looking for the CSS file with versioning. <link href="/xxxxx/themes/xxxxx/css/global.1306108222.css" rel="stylesheet" type="text/css" media="all" /> Anyone like to chip in? Link to comment Share on other sites More sharing options...
bsmooth Posted May 23, 2011 Author Share Posted May 23, 2011 The suggested .htaccess rewrite rule is this #Rules for Versioned Static Files RewriteRule ^(scripts|css)/(.+)\.(.+)\.(js|css)$ $1/$2.$4 [L] Anyone know how to get this to work for the correct path such as /themes/xxxxx/css/global.1194900443.cssThanks. Link to comment Share on other sites More sharing options...
bsmooth Posted May 23, 2011 Author Share Posted May 23, 2011 RewriteRule ^themes/xxxxx/css/global.([^/]+).css /xxxxx/themes/xxxxx/css/global.css [NC,L] # Strip out the version number Use the above rewrite rule. It has been tested on localhost, and it works. Link to comment Share on other sites More sharing options...
haypro Posted December 4, 2015 Share Posted December 4, 2015 Thank you very much! Very useful topic. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now