What are the benefits of improving website performance?

It’s a common place to inject scripts from various places.

I personally prefer more control, but a benefit is that app developers can inject scripts in there instead of directly into your theme. The reason that’s a benefit is because it allows the script to be removed when you uninstall the app.

I’ve optimized a lot of Shopify sites and probably at least half of them have leftover app code loading from uninstalled apps (because apps lose access at the point of uninstall). This prevents that problem.

Ideal solution (in my opinion) would be a section in the Shopify admin where you can control content_for_header and content_for_footer and choose where you want scripts to load, which ones, and on which pages.

Current solution you can employ conditional loading by omitting scripts not needed on certain pages. For example if you find a script in the content_for_header loading on every page but it’s only needed on the product page, you can capture the content_for_header in theme.liquid, then remove the string that loads the script (you’ll have to view source to find it), then use a conditional statement to only load it on the template it’s used for.

2 Likes