A performance case for {{ block.index }} #96
rubenbristian
started this conversation in
General
Replies: 1 comment 1 reply
-
There is a workaround for section-level theme blocks: {%- assign block_index = section.blocks | find_index: 'id', block.id -%} However, that doesn't work for nested blocks. We'll take a look at this at some point! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Some time ago Shopify introduced {{ section.index }} property, which was a huge performance boost, because theme developers can now disable lazyloading of above-the-fold assets and fetch them with priority. There are more complex sections though, that require the use of {{ section.index }} along with {{ block.index }} property in order to determine what elements are actually above the fold, from within the same section. A perfect example of this is the slideshow - while you want to load the first slide's image as fast as possible, you still want to preload the other ones.
With theme blocks this is impossible, and a huge performance drawback. Basic logic like:
Doesn't work anymore in the new architecture. That's one of the biggest reasons why {{ block.index }} is required. There are more, but at least do it for performance.
Beta Was this translation helpful? Give feedback.
All reactions