How can I safely reduce unused Javascript for better site speed?

How can I safely reduce unused Javascript for better site speed?

Jo_Williams1
Tourist
10 0 4

Hi, can anyone offer some advice on how to reduce unused javascript? I'm having issues with my coreweb vitals and mobile site speed. How do I remove the assets/vendors file (in screenshot) (cdn.shopify.com/s/files/1/0197/8160/t/55/assets/vendors.js?v=11282825012671617991659813677) 

and is there a risk of it negatively effecting site once removed?

Many thanks for any advice.

Jo

Prettylittlepartyshop.co.uk

 Screenshot (284).png

 

Replies 8 (8)

Cedcommerce
Shopify Partner
718 77 116

Hello @Jo_Williams1,

We are happy we could help you with this problem. 



It’s an essential way to increase your page speed score. We will definitely help you with this. 

 

For reducing the unused javascript, you need to follow these instructions:-

 

(Note: You are advised to obey this solution if you are technically sound and have knowledge of liquid code)

 

Remove unused apps along with the code

Use scripts under the condition of the theme.liquid file. 

 

For example:- if a script is needed to load on the home page only then you need to set a condition like this

 

{% if template == "index" %}

//script goes here

<script src="{{ script link}}" ></script>

{% endif %}

 

for including script on product page then use this code:-

 

{% if template == "product" %}

//script goes here

<script src="{{ script link}}" ></script>

{% endif %}

for including script on collection page then use this code:-

 

{% if template == "collection" %}

//script goes here

<script src="{{ script link}}" ></script>

{% endif %}

 

Let us know if it works, or if you need more help with this. 

 

You can also check the below link to find a more detailed solution to the issue. 

https://community.shopify.com/c/site-speed/how-to-remove-unused-javascript-and-css/td-p/1740699

 

All the best, 

CedCommerce

CedCommerce || Shopify Expert
- Let us know if our reply is helpful for you. Like it.
- Was your question answered? Mark it as an accepted solution.
- For further discussion contact: Email ID- apps@cedcommerce.com
- Whatsapp:- Join Here
Jo_Williams1
Tourist
10 0 4

Hi thanks very much for responding. I've checked out your solutions page and there are some very helpful tips thank you. I am completely new to this but Google lighthouse says I need to delete unnecessary third party code and suggests vendors.js. Can I delete the whole file or do I need to keep it? To me it simply looks like a license code a something?

I'm very grateful for every piece of advice, can I safely just delete vendors.js?

Many thanks

JoScreenshot (286).jpg

TSSCOM
Visitor
2 0 0

Hi Joy, I am having similar issues with my own store and checking your store in pagespeed all I can say is WOW massive speed upgrade!! Can you share what you did to make such a massive improvement in speed? Did you end up deleting the vendors.js file? Many thanks in advance.

Jo_Williams1
Tourist
10 0 4

No I didn't delete the files as advised against it. In the end I just removed all apps and stripped back page content. What is your store?

Marc_Mayr
Shopify Partner
76 1 14

@Jo_Williams1  we have created an app to solve that exact problem: https://apps.shopify.com/pagespeed-javascript?locale=de

 

It allows you to remove unused javascript from your Shopify store.
https://www.flash-speed.com/ for a full feature overview.

Aasif007
Excursionist
14 0 5

What do we put in //script goes here the whole script?

{% if template == "product" %}

//script goes here

<script src="{{ script link}}" ></script>

{% endif %}

flareAI
Shopify Partner
2405 224 549

Hello @Jo_Williams1,


Gina here from flareAI.

 

If you use less JavaScript on your page, it will reduce the load time of your site.

 

1. Remove all Shopify apps which you are no longer using
Remove the Shopify apps to avoid running code for unused features, and makes your theme code easier to read.
2. Remove third-party JS scripts which you are no longer using
Consider removing code that was added as part of the app install process. To reduce the size of your codebase, you can use optimization techniques such as removing unused functions or variables.
3. Disable theme features you don't use as themes contain CSS, JS, HTML which can increase and affect your store speed
4. Use minified CSS and JS files


Hope this helps,

 

Gina
flareAI: Generate Sales from Google Search, on Autopilot

flareAI : Get Sales from Google Search, on Autopilot
$10+ billion in eCommerce on Google Search, every day. Find out how much you are missing
TSSCOM
Visitor
2 0 0

Hi in the end, I rebuilt our website based on the latest version of the Dawn theme. It fixes all of the speed issues, js issues and just loads much faster. I appreciate that may not be an easy solution for you but ultimately speed matters as you get more traffic and more conversions.