Page 1 of 1

Auto version CSS to update Cache

Posted: Mon May 14, 2012 5:33 am
by speedingorange
Hi All,

Just wondering if anyone could help with this a little,

I want to integrate some code that will automatically update the file name of CSS files when they are changed, preventing users from browsing the site with an out of date CSS.

I found some code here;

http://www.kevinleary.net/simple-update ... ser-cache/

Which looks like it should work, but I am unsure as to which file I should include the php function in that renames the CSS.

Could anyone point me in the right direction, or even confirm if this will work in Opencart .

Many thanks
James

Re: Auto version CSS to update Cache

Posted: Tue May 29, 2012 9:56 pm
by speedingorange
No one?

Re: Auto version CSS to update Cache

Posted: Tue May 29, 2012 11:30 pm
by qahar
The manual way is put version number on stylesheet.

Code: Select all

<link rel="stylesheet" href="catalog/view/theme/default/stylesheet/stylesheet.css?v=1.2.1" media="screen" />
For the automatic way, you can try this:

Header controller:

Code: Select all

$cssFile		= 'catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/stylesheet.css';
$this->data['timeModified']	= date ("dmy", filemtime($cssFile));
Header template:

Code: Select all

<link rel="stylesheet" href="catalog/view/theme/default/stylesheet/stylesheet.css?v=<?php echo $timeModified; ?>" media="screen" />
Result:

Code: Select all

<link rel="stylesheet" href="catalog/view/theme/default/stylesheet/stylesheet.css?v=260512" media="screen" />
The date on stylesheet.css?v=260512 is automatically change based on the file modified date.

Re: Auto version CSS to update Cache

Posted: Thu Sep 06, 2012 10:20 pm
by speedingorange
Works a charm! Thank you so much!

(and that must be the slowest reply ever on here!)

Re: Auto version CSS to update Cache

Posted: Tue Apr 23, 2019 3:18 am
by Lucmac
when it comes to opencart 3 the controller page is :

$data['version'] = filemtime('catalog/view/theme/' . $this->config->get('config_theme') . '/stylesheet/stylesheet.css');

and the header page is:

<link href="catalog/view/theme/default/stylesheet/stylesheet.css?v={{ version }}" rel="stylesheet">