Does anyone know how to stop Knockout HTML templates from being cached (for dev purposes)? I don't have this issue with any other files (CSS, PHTML, XML, JS), it only happens with HTML templates.
As an example I will add the word test to the checkout button in the minicart. The file already exists, the only change I'm making is to add the word test.
<!-- ko i18n: 'Go to Checkout TEST' --><!-- /ko -->
File: app/design/frontend/VENDOR/THEME/Magento_Checkout/web/template/minicart/content.html
These are the steps I usually have to take to display my changes:
- Clear Magento cache (
php bin/magento c:f) - Clear browser cache
- Refresh
No change.
- Clear browser cache again
- Refresh
The change is now visible. This time I got lucky, sometimes it requires more cache clears and other times I give up and delete the caches, var/view_preprocessed and pub/static/frontend.
My questions are:
What causes this?
Why does it only affect HTML files?
Is there a workaround?
-
You should disable Browser Cache. (disable, not clear)Khoa Truong– Khoa Truong2017年03月13日 15:23:42 +00:00Commented Mar 13, 2017 at 15:23
2 Answers 2
From my experience, we should disable Browser Cache when developing. It's one of the way for preventing Browser Cache, not full answer to this quesion.
For example:
Chrome: Network tab> Disable cache
UPDATE:
-Cache on the server side: my team had the same problem with Vagrant box and Puppet. The Puppet Master had the Opcache on the server side. So, the content was cached(can be some days). So, we need to clean the Opcache server.
-
Weirdly that doesn't make a difference, it's still cached somewhere.Ben Crook– Ben Crook2017年03月13日 15:32:41 +00:00Commented Mar 13, 2017 at 15:32
-
This is one of the ways we can use for preventing Browser Cache, not an full answer.Khoa Truong– Khoa Truong2017年03月13日 15:36:31 +00:00Commented Mar 13, 2017 at 15:36
-
1Thank you, everything is appreciated as I'm close to setting my computer on fire as a final solution.Ben Crook– Ben Crook2017年03月13日 15:38:13 +00:00Commented Mar 13, 2017 at 15:38
-
Cache on the server side: my team had the same problem with Vagrant box and Puppet. The Puppet Master had the Opcache on the server side. So, the content was cached(can be some days). So, we need to clean the Opcache server.Khoa Truong– Khoa Truong2017年03月16日 14:01:17 +00:00Commented Mar 16, 2017 at 14:01
-
Thanks. I was looking for this solution from soo long time. Finally i got it. Thanks again.BornCoder– BornCoder2019年08月06日 13:41:07 +00:00Commented Aug 6, 2019 at 13:41
Check deploy mode, If deploy mode is not developer mode then set it.
php bin/magento deploy:mode:set developer
Check .htaccess is in
pub/static/folder or not. If not then please take from fresh magento and add it.Delete this file
pub/static/frontend/<vendor>/<theme>/Magento_Checkout/web/template/minicart/content.htmlDeploy static content
rm -rf pub/static/*
rm -rf var/*
php bin/magento setup:static-content:deploy
-
1Additionally I also had to disable the browser cache as recommended in the answer above. Afterwards, I was finally able to instantly see my changes to the HTML view files after reloading the page in the browser.Louis B.– Louis B.2020年08月11日 06:22:14 +00:00Commented Aug 11, 2020 at 6:22
Explore related questions
See similar questions with these tags.