[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small optimizations to JS loading #190

Merged
merged 1 commit into from
Jul 15, 2021
Merged

Conversation

tyleralsbury
Copy link
Contributor
@tyleralsbury tyleralsbury commented Jul 15, 2021

Why are these changes introduced?

Bundling + changing the positions of a few JS files to be picked up earlier by the browser.

What approach did you take?

Since the JS is deferred, we can put them higher up in the document without them negatively affecting the loading of other files. We can also bundle the JS a bit tighter - removing variants.js and slider.js and putting them, instead, into global.js to remove some network requests.

JS that has the defer attribute will download when it's found in the DOM at low priority, so it won't block the loading of more critical resources, and it will only run after the critical render path is done. By putting the references to these files higher up, we can benefit from them being picked up sooner by the browser and ensure they're ready to go when the rest of the critical path is done downloading.

https://blog.bluetriangle.com/js-delivery-optimization-for-web-performance

Checklist

@ludoboludo ludoboludo self-requested a review July 15, 2021 18:16
Copy link
Contributor
@ludoboludo ludoboludo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One thing I noticed, maybe that can be tweaked here if needed is for the asset loading on the featured-collection section. We're loading all assets with a defer but when using a slow collection it makes it pretty weird. We could most likely at least have template-collection.css loaded right away as when I test on the collection page I don't get the same pricing issue.
video

@tyleralsbury
Copy link
Contributor Author

We could most likely at least have template-collection.css loaded right away

It should be for sure. It's a large file but it contains a lot of things that will cause layout shift if it's excluded. We'll need to make another pass over the theme to fix layout shift at some point. It crops back up occasionally as things change and move around.

@tyleralsbury tyleralsbury merged commit 0862e60 into main Jul 15, 2021
@tyleralsbury tyleralsbury deleted the slight-js-optimization branch July 15, 2021 19:57
@baldurh
Copy link
Contributor
baldurh commented Jul 16, 2021

I thought in today's world of http/2 bundling too much was discouraged. Were there any specific problems with having variants.js and slider.js separate from global.js? Also, isn't this forcing users to download unnecessary code on most pages?

phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants