Post by speedingorange » Mon May 14, 2012 5:33 am

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

Active Member

Posts

Joined
Tue Feb 23, 2010 7:33 pm

Post by speedingorange » Tue May 29, 2012 9:56 pm

No one?

Active Member

Posts

Joined
Tue Feb 23, 2010 7:33 pm

Post by qahar » Tue May 29, 2012 11:30 pm

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.

User avatar
Expert Member

Posts

Joined
Tue Jun 29, 2010 10:24 pm
Location - Indonesia

Post by speedingorange » Thu Sep 06, 2012 10:20 pm

Works a charm! Thank you so much!

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

Active Member

Posts

Joined
Tue Feb 23, 2010 7:33 pm

Post by Lucmac » Tue Apr 23, 2019 3:18 am

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">

New member

Posts

Joined
Mon Apr 22, 2019 5:29 pm
Who is online

Users browsing this forum: No registered users and 29 guests