Solved

Is it better performance to check product tags in liquid or javascript?

Timed_Ecom
Shopify Partner
39 1 9

We have a store that has some vue.js slapped in it and curious to know what is a better way to check against product tags in regards to store performance. 


Example 1:

 

 

 

<script>
var checkProduct = false
{% if product.tags contains 'whatever' %}
var checkProduct = true
{% endif %}
</script>

 

 

 


Example 2:

Since we store product data on the vue model i can check against them with

 

 

 

<script>
if(product_data.tags.includes('whatever') {
vm.checkProduct = true
}
</script>

 

 

 



Is there any benefit in doing either way of the above in regards to performance?

If i put liquid inside of a script tag does it just convert it to it's js equivalent anyway when it renders? And if it does then it would mean that there's no real difference?

Thank you

 

Accepted Solution (1)

MichalKopec
Excursionist
37 5 4

This is an accepted solution.

The version with liquid tags will put more processing on the server so the response of the can be marginally slower. When there's a lot of requests this can make a difference. Without doing any testing for speed between the two I'd choose the JavaScript option.

View solution in original post

Reply 1 (1)

MichalKopec
Excursionist
37 5 4

This is an accepted solution.

The version with liquid tags will put more processing on the server so the response of the can be marginally slower. When there's a lot of requests this can make a difference. Without doing any testing for speed between the two I'd choose the JavaScript option.