5

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:

  1. Clear Magento cache (php bin/magento c:f)
  2. Clear browser cache
  3. Refresh

No change.

  1. Clear browser cache again
  2. 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?

1
  • You should disable Browser Cache. (disable, not clear) Mar 13, 2017 at 15:23

2 Answers 2

6

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

enter image description here

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.

5
  • Weirdly that doesn't make a difference, it's still cached somewhere.
    – Ben Crook
    Mar 13, 2017 at 15:32
  • This is one of the ways we can use for preventing Browser Cache, not an full answer. Mar 13, 2017 at 15:36
  • 1
    Thank you, everything is appreciated as I'm close to setting my computer on fire as a final solution.
    – Ben Crook
    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. Mar 16, 2017 at 14:01
  • Thanks. I was looking for this solution from soo long time. Finally i got it. Thanks again.
    – BornCoder
    Aug 6, 2019 at 13:41
1
  1. Check deploy mode, If deploy mode is not developer mode then set it.

    php bin/magento deploy:mode:set developer

  2. Check .htaccess is in pub/static/ folder or not. If not then please take from fresh magento and add it.

  3. Delete this file pub/static/frontend/<vendor>/<theme>/Magento_Checkout/web/template/minicart/content.html

  4. Deploy static content

rm -rf pub/static/*

rm -rf var/*

php bin/magento setup:static-content:deploy

1
  • 1
    Additionally 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.
    Aug 11, 2020 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.