Ad

Shopify Liquid - Does Lots Of Logic SLOW DOWN Page Load?

- 1 answer

  • If I have 30-40 if-statements and other Liquid logic on a page to check different things about the product for example... will that slow down page load? (Or will this be an issue only after hundreds or thousands of if-statements only?)

  • Do Shopify template files even render when a visitor opens a web page in real time, or do they actually render as static files in advance, once I click "save" on a product or theme settings?

Thanks!

Ad

Answer

Shopify sites do render on page load however there is some caching too.

If you add:

{{ 'now' | date: '%s' }}

you will be able to see the time change on a per second basis. Although this is cool it isn't very reliable for time based functions because of the caching.

Having 30 - 40 if statements may cause some performance issues, but Shopify is running on pretty speedy AWS servers so I rarely notice any speed drops from overly complex pages. I have created large files of if statements that include different files on certain conditions and haven't noticed any problems.

Try checking out the network tab and seeing how long it takes to return a response from the first request.

If you are experiencing performance issues try replacing the if statements with a {% case %} statement instead and make use of {% continue %} and {% break %} in for loops.

Ad
source: stackoverflow.com
Ad