How to prevent loading of unused JavaScript file

nikolasburk
New Member
1 0 5

Hey everyone! I have a Shopify site that has quite a bit optimization potential that I'd like to squeeze out. 

This is Google's PageSpeed test for one of the pages: https://developers.google.com/speed/pagespeed/insights/?hl=de&url=https%3A%2F%2Fwww.urbankunst.de%2F...

image.png

 

As you can see, there's quite a bit of unused JavaScript that I'd like to get rid of.

Specifically I want to start by removing the top file: https://connect.facebook.net/signals/config/576182329255766?v=2.9.21&r=stable

I now searched through the source files in my Shopify project (using this Chrome extension) for a reference to that file, but couldn't find anything! Does anyone know a way how I can find out from where this JS file loaded into my site and how I can remove it?

We have this same exact question.  We've removed our FB Pixel, yet per google page speed report the unused fb pixel javascript is slowing down our site, but we can't figure out how to remove it.

 

Daniel_Kaplan_0-1598748626727.png

 

Note we did already remove the Shopify Install of the FB Pixel 

Daniel_Kaplan_0-1598748864362.png

As a test, we even tried adding a '123' to it subsequently and found that just added 2 fb pixel ids.

 

Any help greatly appreciated!

 

 

0 Likes

I wonder that too and to be honest, although I'd like to be wrong, I don't think it's possible since those files are coming from external sources.

The only solution I found was to reduce third party apps/scripts the most I can. 

I have thought about a few things like:

1. Identifying and removing scripts before loading the page (adding them right above </head>)

document.querySelector(`script[src*='facebook']`).remove()

2. Also I have seen solutions in the past by companies doing speed optimizations with Shopify that is something like this:

  <script>
    setTimeout(function() {
      function asyncLoad() {
        var urls = ["\/\/d1liekpayvooaz.cloudfront.net\/apps\/coin\/coin.js?shop=zenir.myshopify.com","https:\/\/recovermycart.com\/RememberMyCart\/Manage\/CartJS?shop=zenir.myshopify.com\u0026shop=zenir.myshopify.com","https:\/\/qb.boldapps.net\/quantity_breaks.php?shop=zenir.myshopify.com","https:\/\/loox.io\/widget\/N1ZIsn19fS\/loox.js?shop=zenir.myshopify.com"];
        for (var i = 0; i <urls.length; i++) {
          var s = document.createElement('script');
          s.type = 'text/javascript';
          s.async = true;
          s.src=urls[i];
          var x = document.getElementsByTagName('script')[0];
          x.parentNode.insertBefore(s, x);
        }
      };
      if(window.attachEvent) {
        window.attachEvent('onload', asyncLoad);
      } else {
        window.addEventListener('load', asyncLoad, false);
      }
    },6000)();
</script>


the urls variable is added manually. In every Shopify store you can find a list of all the Javascript being injected by the apps, so basically their intent was to load the apps later (?) I'm not entirely sure, but I'm leaving it here if anyone wants to play around with it.

Anyhow, please do let me know if you find a solution!

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Using a free theme? Improve it with copy/paste code snippets clicking here.
◦ Looking to hire an experienced developer? Same day response: ezfycode@gmail.com.
0 Likes
Astra_and_Nick
Excursionist
17 0 4

Does anyone know a way how I can find out from where this JS file loaded into my site and how I can remove it?

 

I have been going crazy with this for the past 5 days.  In addition to removing the FB pixel (in shopify) - have also uninstalled the FB shopping app - and tried to remove the connection to our site (and the pixel) from within the Facebook Business Manager.  Absolutely nothing seems to make a difference?  

 

Even when I view the Source Code of our pages - nothing related to this FB file is found anywhere - So - where is it coming from?

ByteSize
Tourist
6 0 1

Under your settings_data.json,

 

Change your 

"share_facebook": true, 

 

To

 

"share_facebook": false,

 

Like if this helped you.

0 Likes
hockey2112
New Member
1 0 0

This did not help me. Has anyone figured out a solution?

0 Likes