Jump to content

Client Side Cache Control?


derthis

Recommended Posts

Hi,

 

I have developed a website in PrestaShop, now I am in a process of redesigning it, and I am thining about how to deploy this new design to a already in-production site.

 

The problem is when I deploy even a little change, I turn off smarty cache, I turn on compile_check=on, disable all CCC and CC.. Even then when I open the website, there is an old version of it, cached in my browser. I can see all the changes by pressing cmd+R or F5, but - I have to do this reload on every single page type (i.e. homepage, product page, category page, cms page..) and BUT - I fear my clients won't think of pressing cmd+r or F5 (returning ones) - they will just see the broken page design!

 

I really worry about those returning clients who may not be so experienced and may not clean their cache. Therefore I really worry about deploying all those big changes in design.

 

Any ideas how to solve this, e.g. setting expires in headers? how? or will renaming the theme force browser to reload css and js? or something else?

 

Problematic are the CSS (and perhaps JS files).

 

Thanks for your ideas.

Link to comment
Share on other sites

Found this topic: http://www.prestashop.com/forums/topic/136126-auto-versioning-css-files-force-css-refresh/

 

Well, it seems to be as easy as adding a file in override/classes called Tools.php with this content:

 

<?php
class Tools extends ToolsCore
{
//credit: http://particletree....vascript-files/
public static function autoVer($url){
	 $path = pathinfo($url);

	 if(file_exists($_SERVER['DOCUMENT_ROOT'].$url))
			 $ver = filemtime($_SERVER['DOCUMENT_ROOT'].$url);
	 else
			 $ver = '1';
	 return $path['dirname'].'/'.$path['basename'].'?v='.$ver;
}

public static function addCSS($css_uri, $css_media_type = 'all')
{
			 global $css_files;
			 if (is_array($css_uri))
			 {
							 foreach ($css_uri as $file => $media_type)
											 self::addCSS($file, $media_type);
							 return true;
			 }
			 //overriding of modules css files
			 $different = 0;
			 $override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
			 if ($different && file_exists($override_path))
							 $css_uri = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
			 else
			 {
							 // remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
							 $url_data = parse_url($css_uri);
							 $file_uri = _PS_ROOT_DIR_.self::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
							 // check if css files exists
							 if (!file_exists($file_uri))
											 return true;
			 }
			 // detect mass add
			 $css_uri = array(Tools::autoVer($css_uri) => $css_media_type);//This is the only line that has been changed to add in the call to the new autoVer function we created above.
			 // adding file to the big array...
			 if (is_array($css_files))
							 $css_files = array_merge($css_files, $css_uri);
			 else
							 $css_files = $css_uri;
			 return true;
}
}
?>

 

Now CSS has version in it and it should force the browser to download it every time.

Link to comment
Share on other sites

  • 3 weeks later...

Found this topic: http://www.prestasho...ce-css-refresh/

 

Well, it seems to be as easy as adding a file in override/classes called Tools.php with this content:

 

<?php
class Tools extends ToolsCore
{
//credit: http://particletree....vascript-files/
public static function autoVer($url){
	 $path = pathinfo($url);

	 if(file_exists($_SERVER['DOCUMENT_ROOT'].$url))
			 $ver = filemtime($_SERVER['DOCUMENT_ROOT'].$url);
	 else
			 $ver = '1';
	 return $path['dirname'].'/'.$path['basename'].'?v='.$ver;
}

public static function addCSS($css_uri, $css_media_type = 'all')
{
			 global $css_files;
			 if (is_array($css_uri))
			 {
							 foreach ($css_uri as $file => $media_type)
											 self::addCSS($file, $media_type);
							 return true;
			 }
			 //overriding of modules css files
			 $different = 0;
			 $override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
			 if ($different && file_exists($override_path))
							 $css_uri = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
			 else
			 {
							 // remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
							 $url_data = parse_url($css_uri);
							 $file_uri = _PS_ROOT_DIR_.self::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
							 // check if css files exists
							 if (!file_exists($file_uri))
											 return true;
			 }
			 // detect mass add
			 $css_uri = array(Tools::autoVer($css_uri) => $css_media_type);//This is the only line that has been changed to add in the call to the new autoVer function we created above.
			 // adding file to the big array...
			 if (is_array($css_files))
							 $css_files = array_merge($css_files, $css_uri);
			 else
							 $css_files = $css_uri;
			 return true;
}
}
?>

 

Now CSS has version in it and it should force the browser to download it every time.

 

Doesn't work properly on presta 1.4.8.2

CSS does actually have version, but the browser don't download it every time and, if combined with BO caching, it may cause header refresh problems

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...