Reducing unused Javascript to improve Core Web Vitals

Marc_Mayr
Shopify Partner
73 1 11

Hey Shopify Community,
we are running a Shopify Plus store for 2 years now and our main problem is that a lot of functionality only comes with apps or we'd have to custom code them which would take unnecessary resources to do work that already has been done. The main problem with apps is that they inject Javascript into every page, even tho some apps are only needed on specific ones like cart, product, home or content pages.

 

Therefor we stumbled across a solution from another member @PageFly-Richard (thanks for the hint!) to comment out the {{ content_for_header }} which is definitely a solution, but doesn't let you load specific apps on specific pages.

We spun it further and created rules to strip only specific javascript (apps) on specific pages. The results were satisfying and we decided to release an app doing exactly that. https://apps.shopify.com/pagespeed-javascript

CL32gJHdy_MCEAE=.jpeg

We are happy for any feedback, improvements, bugs you report. It should definitely help stores with a lot of apps installed.

Reply 1 (1)

kazi
Shopify Partner
577 87 109

@Marc_Mayr  you can load scripts where they needed 

ex:

 

{% if template != "index" %}

{% include 'custom.js' %}
{% endif %}

 

custom.js  will load on every pages except home

 

{% if template contains 'cart' %}

{% include 'cart.js' %}
{% endif %}

 

cart.js  will load on cart pages only

▶️ If you need more help with your Shopify store
Speed Optimization | Theme Customization ? ☎️ WhatsApp ✉️Email Skype: kof.bd