Post by Dreamvention » Fri Aug 17, 2018 3:28 pm

Hi Guys

We have been getting soom feedback about users having issues with browser cache. It happens like this:
- you added a product to cart and clicked back and there is zero in your cart. only after refresh, you see the products.
- you installed a new extension, went back to see it and it is not there.
- you added a new product - not showing in list.
- you added a new category - still missing.

this issue is common because of twig and one more - the browser's cache.

Here is the solution
1. go to Dashboard, on the top right you will see a button (blue gear)
2. click the blue gear button and in the popup - turn off the cache and click orange button (refresh)
3. via FTP go to your root folder (public_html or www) and find admin folder
4. in admin folder create a new .htaccess file and edit it

add this code to .htaccess

Code: Select all

<IfModule mod_headers.c>
 <filesMatch "\.(htm|html|css|js|php|tag)$">
   Header set Cache-Control "no-cache, no-store, must-revalidate"
 </filesMatch>
</IfModule>
this should clear the twig cache and also remove the browser cache.

Let me know if this helped anyone?

Many OpenCart users struggle to find quality extensions. We know how frustrating the need to fix the shop is just because of one poorly coded extension. We created quality OpenCart Extensions, tested by real developers and provide professional support.

AJAX QUICK CHECKOUT - #1 one-page checkout solution
VISUAL DESIGNER - Page builder for Opencart
View more extensions here

Tested by Shopunity.net


User avatar
Administrator

Posts

Joined
Sun Jun 17, 2012 7:04 pm
Location - Europe

Post by stq137 » Fri May 08, 2020 8:52 pm

Dreamvention wrote:
Fri Aug 17, 2018 3:28 pm
Hi Guys

We have been getting soom feedback about users having issues with browser cache. It happens like this:
- you added a product to cart and clicked back and there is zero in your cart. only after refresh, you see the products.
- you installed a new extension, went back to see it and it is not there.
- you added a new product - not showing in list.
- you added a new category - still missing.

this issue is common because of twig and one more - the browser's cache.

Here is the solution
1. go to Dashboard, on the top right you will see a button (blue gear)
2. click the blue gear button and in the popup - turn off the cache and click orange button (refresh)
3. via FTP go to your root folder (public_html or www) and find admin folder
4. in admin folder create a new .htaccess file and edit it

add this code to .htaccess

<IfModule mod_headers.c>
<filesMatch "\.(htm|html|css|js|php|tag)$">
Header set Cache-Control "no-cache, no-store, must-revalidate"
</filesMatch>
</IfModule>

this should clear the twig cache and also remove the browser cache.

Let me know if this helped anyone?
O0 works like magic
thank you

Newbie

Posts

Joined
Sun Mar 15, 2020 1:23 am

Post by stq137 » Fri May 08, 2020 9:11 pm

But with your solution, after adding items to cart then clicking store logo, the cart will lose all the items in it !!

how can we fix this ?

Newbie

Posts

Joined
Sun Mar 15, 2020 1:23 am

Post by ADD Creative » Fri May 08, 2020 9:34 pm

This has been reported here. https://github.com/opencart/opencart/issues/7008

The solution posted in this thread is wrong. You should not tell the browser not to cache static files such as .css and .js. This will adversely affect customer experience and increase server load.

The easiest way to fix the lack of cache control headers issue is by making the following change to the framework, since the session is always started. This will ensure the cache control header will only be set when needed.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

$response->addHeader('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by stq137 » Fri May 08, 2020 9:49 pm

ADD Creative wrote:
Fri May 08, 2020 9:34 pm
This has been reported here. https://github.com/opencart/opencart/issues/7008

The solution posted in this thread is wrong. You should not tell the browser not to cache static files such as .css and .js. This will adversely affect customer experience and increase server load.

The easiest way to fix the lack of cache control headers issue is by making the following change to the framework, since the session is always started. This will ensure the cache control header will only be set when needed.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

$response->addHeader('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');
So much better, thank you very much for your pass. :D

Newbie

Posts

Joined
Sun Mar 15, 2020 1:23 am

Post by peiyichloe20 » Wed Jun 03, 2020 9:02 pm

ADD Creative wrote:
Fri May 08, 2020 9:34 pm
This has been reported here. https://github.com/opencart/opencart/issues/7008

The solution posted in this thread is wrong. You should not tell the browser not to cache static files such as .css and .js. This will adversely affect customer experience and increase server load.

The easiest way to fix the lack of cache control headers issue is by making the following change to the framework, since the session is always started. This will ensure the cache control header will only be set when needed.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

$response->addHeader('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');

hello,
it works! thank you so much

but there is another problem
it works when i adjust the amount by add/minus button
but if i manually enter the designated amount, it doesnt work

do you know how to deal with it then?
thank you so much!

Newbie

Posts

Joined
Fri Feb 14, 2020 4:54 pm

Post by ADD Creative » Thu Jun 04, 2020 5:58 pm

The default theme doesn't have plus and minus buttons. This suggests your theme has modified the the add to cart functions. If you can, try the default theme as a test. You may have to contact the theme developer for support.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by iamstevenelson » Sat Aug 21, 2021 8:57 pm

This is your server's issue not Opencart's. Please contact your hosting provider and ask them to change your PHP version from fast CGI to normal CGI version. Disable mod_security if enabled. This should fix this cache issue. I have got the same issue and mine is fixed by this method.

User avatar
New member

Posts

Joined
Sat May 02, 2015 11:56 am

Post by ADD Creative » Sat Aug 21, 2021 9:10 pm

iamstevenelson wrote:
Sat Aug 21, 2021 8:57 pm
This is your server's issue not Opencart's. Please contact your hosting provider and ask them to change your PHP version from fast CGI to normal CGI version. Disable mod_security if enabled. This should fix this cache issue. I have got the same issue and mine is fixed by this method.
It was probably some other default settings that got changed at the same time you made your changes. What you propose would not directly affect the cache control headers.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Druvan » Sun May 22, 2022 5:59 am

ADD Creative wrote:
Fri May 08, 2020 9:34 pm
This has been reported here. https://github.com/opencart/opencart/issues/7008

The solution posted in this thread is wrong. You should not tell the browser not to cache static files such as .css and .js. This will adversely affect customer experience and increase server load.

The easiest way to fix the lack of cache control headers issue is by making the following change to the framework, since the session is always started. This will ensure the cache control header will only be set when needed.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

$response->addHeader('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');
Hello!
Thanks for good work. Just want to check. What's the best solution?
Using version 3.0.2.0

Github: https://github.com/opencart/opencart/issues/7008
Two other files are suppose to be changed?

In system framework.php
Line: $response->addHeader('Content-Type: text/html; charset=utf-8');
This line I have three times in framework.php
Cheers!

New member

Posts

Joined
Mon Aug 08, 2016 5:39 am

Post by ADD Creative » Sun May 22, 2022 5:59 pm

Druvan wrote:
Sun May 22, 2022 5:59 am
ADD Creative wrote:
Fri May 08, 2020 9:34 pm
This has been reported here. https://github.com/opencart/opencart/issues/7008

The solution posted in this thread is wrong. You should not tell the browser not to cache static files such as .css and .js. This will adversely affect customer experience and increase server load.

The easiest way to fix the lack of cache control headers issue is by making the following change to the framework, since the session is always started. This will ensure the cache control header will only be set when needed.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

$response->addHeader('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');
Hello!
Thanks for good work. Just want to check. What's the best solution?
Using version 3.0.2.0

Github: https://github.com/opencart/opencart/issues/7008
Two other files are suppose to be changed?

In system framework.php
Line: $response->addHeader('Content-Type: text/html; charset=utf-8');
This line I have three times in framework.php
Cheers!
Ideally it should be added to the session start up, but adding to the framework is easier and will give the same result. You should only have one line setting the charset in framework.php. You will probably need to compare this against an original file to see why yours is different.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Druvan » Mon May 23, 2022 5:41 am

ADD Creative wrote:
Sun May 22, 2022 5:59 pm
Druvan wrote:
Sun May 22, 2022 5:59 am
ADD Creative wrote:
Fri May 08, 2020 9:34 pm
This has been reported here. https://github.com/opencart/opencart/issues/7008

The solution posted in this thread is wrong. You should not tell the browser not to cache static files such as .css and .js. This will adversely affect customer experience and increase server load.

The easiest way to fix the lack of cache control headers issue is by making the following change to the framework, since the session is always started. This will ensure the cache control header will only be set when needed.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

$response->addHeader('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
$response->addHeader('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$response->addHeader('Pragma: no-cache');
Hello!
Thanks for good work. Just want to check. What's the best solution?
Using version 3.0.2.0

Github: https://github.com/opencart/opencart/issues/7008
Two other files are suppose to be changed?

In system framework.php
Line: $response->addHeader('Content-Type: text/html; charset=utf-8');
This line I have three times in framework.php
Cheers!
Ideally it should be added to the session start up, but adding to the framework is easier and will give the same result. You should only have one line setting the charset in framework.php. You will probably need to compare this against an original file to see why yours is different.
Hello,
Just download original version again and see that my file is 3x bigger.
I have not made the update myself and maybe why yours solution not working for me.
Attached file. Site is running with no errors but no sure if just to overwrite file.
Maybe some extensions not running?
What you think?

New member

Posts

Joined
Mon Aug 08, 2016 5:39 am

Post by ADD Creative » Mon May 23, 2022 6:01 pm

Druvan wrote:
Mon May 23, 2022 5:41 am
Hello,
Just download original version again and see that my file is 3x bigger.
I have not made the update myself and maybe why yours solution not working for me.
Attached file. Site is running with no errors but no sure if just to overwrite file.
Maybe some extensions not running?
What you think?
Looks like you have some extension or modification that replaces the framework.php file. On quickly looking at the file you need to add the extra headers after the last two $response->addHeader('Content-Type: text/html; charset=utf-8'); lines and not the first two.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by ADD Creative » Thu Feb 09, 2023 10:34 pm

I've noticed recently that Firefox aggressively caches redirects, which can lead to some other strange issues.

So using header() rather than $response->addHeader() would be better as the later doesn't apply to redirects.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

header('Expires: Thu, 19 Nov 1981 08:52:00 GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true);
header('Pragma: no-cache', true);

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Druvan » Thu Jul 06, 2023 5:22 am

You mean it should look like this?
This is for v3.0.2.0

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true);
header('Pragma: no-cache', true);
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);

New member

Posts

Joined
Mon Aug 08, 2016 5:39 am

Post by Druvan » Thu Jul 06, 2023 5:54 am

ADD Creative wrote:
Thu Feb 09, 2023 10:34 pm
I've noticed recently that Firefox aggressively caches redirects, which can lead to some other strange issues.

So using header() rather than $response->addHeader() would be better as the later doesn't apply to redirects.

In system/framework.php find the following line at around line 74.

Code: Select all

$response->addHeader('Content-Type: text/html; charset=utf-8');
After that line add the following.

Code: Select all

header('Expires: Thu, 19 Nov 1981 08:52:00 GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true);
header('Pragma: no-cache', true);
Hey there,
Just tried the above. I use Mozilla.
It will not autoupdate the admin list after I copy a product.
Still the same, copy with no error but admin list will not update.
Do not know if you same as me.
I write a keyword like: clothes
Copy a product.
I get success message. No update in admin list.
If I now write keyword: cloth
The new will show up

New member

Posts

Joined
Mon Aug 08, 2016 5:39 am

Post by ADD Creative » Thu Jul 06, 2023 6:52 am

Druvan wrote:
Thu Jul 06, 2023 5:22 am
You mean it should look like this?
This is for v3.0.2.0

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true);
header('Pragma: no-cache', true);
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);
Yes that would be the change.
Druvan wrote:
Thu Jul 06, 2023 5:54 am
Hey there,
Just tried the above. I use Mozilla.
It will not autoupdate the admin list after I copy a product.
Still the same, copy with no error but admin list will not update.
Do not know if you same as me.
I write a keyword like: clothes
Copy a product.
I get success message. No update in admin list.
If I now write keyword: cloth
The new will show up
Once you have made the change you may need to clear you browser cache as it may still have old pages cached.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Druvan » Sat Jul 08, 2023 5:00 pm

ADD Creative wrote:
Thu Jul 06, 2023 6:52 am
Druvan wrote:
Thu Jul 06, 2023 5:22 am
You mean it should look like this?
This is for v3.0.2.0

// Response
$response = new Response();
$response->addHeader('Content-Type: text/html; charset=utf-8');
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT', true);
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0', true);
header('Pragma: no-cache', true);
$response->setCompression($config->get('config_compression'));
$registry->set('response', $response);
Yes that would be the change.
Druvan wrote:
Thu Jul 06, 2023 5:54 am
Hey there,
Just tried the above. I use Mozilla.
It will not autoupdate the admin list after I copy a product.
Still the same, copy with no error but admin list will not update.
Do not know if you same as me.
I write a keyword like: clothes
Copy a product.
I get success message. No update in admin list.
If I now write keyword: cloth
The new will show up
Once you have made the change you may need to clear you browser cache as it may still have old pages cached.
How do you mean with this.
Can this be a token problem?
Should I clear browser cache when I updated a product?
Are there any other option to turn off cache for admin page?

New member

Posts

Joined
Mon Aug 08, 2016 5:39 am

Post by ADD Creative » Sat Jul 08, 2023 7:46 pm

Druvan wrote:
Sat Jul 08, 2023 5:00 pm
How do you mean with this.
Can this be a token problem?
Should I clear browser cache when I updated a product?
Are there any other option to turn off cache for admin page?
I mean after you make the changes to system/framework.php to clear your browser cache.

I think you would be better stating your own topic and explain more clearly what the issue is. A step by step guide on how to recreate the error. Also give as much information as you can, as well as your OpenCart version, give your PHP version, theme and any extensions used. Even a link to your site. If you are using any third party cache or proxy, such as CloudFlare. Any errors that show in both the PHP and OpenCart error logs. Any error in your web browser's developer console.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: No registered users and 181 guests