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
The manual way is put version number on stylesheet.
For the automatic way, you can try this:
Header controller:
Header template:
Result:
The date on stylesheet.css?v=260512 is automatically change based on the file modified date.
Code: Select all
<link rel="stylesheet" href="catalog/view/theme/default/stylesheet/stylesheet.css?v=1.2.1" media="screen" />
Header controller:
Code: Select all
$cssFile = 'catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/stylesheet.css';
$this->data['timeModified'] = date ("dmy", filemtime($cssFile));
Code: Select all
<link rel="stylesheet" href="catalog/view/theme/default/stylesheet/stylesheet.css?v=<?php echo $timeModified; ?>" media="screen" />
Code: Select all
<link rel="stylesheet" href="catalog/view/theme/default/stylesheet/stylesheet.css?v=260512" media="screen" />
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">
$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">
Who is online
Users browsing this forum: No registered users and 29 guests