Code inside {% javascript %} always show the previous version

Code inside {% javascript %} always show the previous version

ivanbarcia
Shopify Partner
2 0 0

Hi, I detected strange behavior working with the Liquid tag {% javascript %}.

 

I move to other file some of the custom components created by default in the Dawn theme, but I do not change the JS code. All seemed to work well, and I deployed to production. In production, this code not works properly, and after a long time debugging it, I found that the code inside {% javascript %} always show the previous state of code, like there's a cache or something.

 

For instance:

1. I create a console.log("a") in my code, inside the {% javascript %} tag, and save it.

2. The web console not shows nothing.

3. I modify the console log to console.log("b") and save it.

4. The web console shows "a".

5. I remove the console.log and save it.

6. The web console shows "b".

 

This happens in local (with Shopify CLI) and in production.

 

- Dawn v.7.0.1

- Shopify CLI and GitHub integration

Replies 2 (2)

LitCommerce
Astronaut
2860 684 760

Hi @ivanbarcia,

You can change:

{% javascript %} => <script>

it will work fine. Refer https://shopify.dev/themes/architecture/sections/section-assets#javascript

Hope it helps!

 

LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool.
Effortlessly sell on biggest marketplaces like Amazon, Etsy, eBay, Facebook etc with bulk listing tool, real-time sync & smart order management. Use LitCommerce free for 1-year now!
ivanbarcia
Shopify Partner
2 0 0

Thanks for your reply. That is not very correct on many occasions. If we are dealing with a section that is used in different places, you may be loading the same JS several times. That's what{% javascript %} avoids and that's why I was trying to use it in this case.