JavaScript Error on script load - LightJSExclude

Michael_Marsell
Shopify Partner
1 0 4

Hi there,

 

A client of ours (empireskateshop.myshopify.com) has noticed that our widget no longer loads on their website.

 

There is a console error showing that the function lightJsExclude is undefined. This looks like an error on Shopify's side. I've submitted a support ticket, but they directed me here instead.

 

It looks like this gets added when an app using lightJS is installed so that the type can be set correctly. Our widget does not use lightJS, but is affected as all third-party scripts are prevented from loading.

 

Short of installing each app that our client uses and seeing which one triggers this change, I don't know if this can be fixed.

 

Has anyone come across this before and/or found a way around this?

 

 

Michael_Marsell_0-1657064801846.png

Screenshot 2022-07-06 114921.jpg

 

Replies 10 (10)

KB77
Shopify Staff
59 6 11

Hi @Michael_Marsell . 

In this case if you would like us to investigate the bug report we will  require further information on how the app in question is interacting with the API  such as the request body and headers, as well any response errors and response headers (x-request-id, cursor) from the error. Our API team can then take a look using internal tools and logs. If you can submit this issue using the Report an Issue Form here https://help.shopify.com/en/questions/partners#/contact/report-an-issue it will help expedite the process as this will enable us to authenticate access where necessary. Thank you. 

KB77 | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Sergey
Shopify Partner
23 0 7

Hey @KB77. Michael has already provided necessary details, so your response doesn't look relevant for me at all. Let me expand:
1. how the app in question is interacting with the API  such as the request body and headers – this is not about the app at all, this in about loading scripts how showed on the screenshot, so this request of details is not relevant here
2. as well any response errors and response headers (x-request-id, cursor) from the error – just read the post, open the store (the store in the post was fixed, you can open one that I reported) and see the error, headers are not relevant here
3. If you can submit this issue using the Report an Issue Form here https://help.shopify.com/en/questions/partners#/contact/report-an-issue it will help expedite the process as this will enable us to authenticate access where necessary. – Michael mentioned "I've submitted a support ticket, but they directed me here instead."

Thank you.

Built more than 10 public Shopify apps for clients, with partners and our own – https://asoft.co

Sergey
Shopify Partner
23 0 7

Thanks for collecting all details @Michael_Marsell.

Exactly the same issue happened to our client (marjory-warren-boutique.myshopify.com). They reached out asking for help. I have nothing to add at this moment to what Michael wrote. Seems like an issue from Shopify.

The following code from the online store doesn't work because of ReferenceError: Can't find variable: lightJsExclude

 

 

(function() {
  function asyncLoad() {
    var urls = ["\/\/shopify.privy.com\/widget.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/tracking.finditquick.com\/retargeting_init.php?account=30257\u0026shop=marjory-warren-boutique.myshopify.com","https:\/\/cdn.hextom.com\/js\/quickannouncementbar.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/d5zu2f4xvqanl.cloudfront.net\/4\/fe\/loader_2.js?shop=marjory-warren-boutique.myshopify.com","\/\/staticw2.yotpo.com\/MwYawkrKZ7hdD5DetwWzvdcdPsgmmQpxs6OdSKds\/widget.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/d2oc6krkhhy4rs.cloudfront.net\/scripts\/script-marjory-warren-boutique-1657538629.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/seo.apps.avada .io\/scripttag\/avada-seo-installed.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/cdn1.avada. .io\/flying-pages\/module.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/assets.givz.com\/widgets\/shopify\/pre-purchase\/latest\/givz.min.js?shop=marjory-warren-boutique.myshopify.com","https:\/\/pop-convert-script.netlify.app\/production.pc.min.js?unique_id=marjory-warren-boutique.myshopify.com\u0026shop=marjory-warren-boutique.myshopify.com","","","","","","","https:\/\/tools.luckyorange.com\/core\/lo.js?site-id=d0ab7806\u0026shop=marjory-warren-boutique.myshopify.com","https:\/\/cdn.shopify.com\/shopifycloud\/shopify_chat\/storefront\/shopifyChatV1.js?api_env=production\u0026button_color=%23f47048\u0026button_style=text\u0026i=chat_bubble\u0026p=bottom_right\u0026shop_id=XULLZSoJjgnpaZ4dKjQGM_PuF_nV5t37PsioUYLALCo\u0026t=chat_with_us\u0026shop=marjory-warren-boutique.myshopify.com"];
    for (var i = 0; i < urls.length; i++) {
      var s = document.createElement('script');
      if (lightJsExclude.indexOf(urls[i]) === -1) s.type = 'lightJs'; else 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);
  }
})();

 

 


 

Built more than 10 public Shopify apps for clients, with partners and our own – https://asoft.co
hjkl
Shopify Partner
2 0 0

Does anyone know what that "loader_2.js" script is? It got flagged by AVG as malware on a WordPress site I'm working on. It looks like some random cloudfront subdomain: d5zu2f4xvqanl.cloudfront.net/42/fe/loader_2.js

 

If it were from Shopify, I'd expect a real domain name.

Sergey
Shopify Partner
23 0 7

This is really surprising that my previous reply where I mentioned the same issue simply disappeared... I have to write again. Also my experience posting here was awful – different unexpected errors before posting, couldn't make a list 1, 2, 3 using this rich editor. Just irrelevant piece of feedback to what Shopify built lately.

Built more than 10 public Shopify apps for clients, with partners and our own – https://asoft.co

Sergey
Shopify Partner
23 0 7

Hi @Michael_Marsell. Thanks for submitting all details. I have exactly the same case as yours. Our app client messaged us asking for help and I found out this post. The app scripts simply do not load on their store.

Store: https://marjory-warren-boutique.myshopify.com
Error: ReferenceError: Can't find variable: lightJsExclude
Severity: Critical
Script:

(function() {
  function asyncLoad() {
    var urls = ["\/\/shopifyDOTprivyDOTcom\/widgetDOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/trackingDOTfinditquickDOTcom\/retargeting_initDOTphp?account=30257\u0026shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/cdnDOThextomDOTcom\/js\/quickannouncementbarDOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/d5zu2f4xvqanlDOTcloudfrontDOTnet\/4\/fe\/loader_2DOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","\/\/staticw2DOTyotpoDOTcom\/MwYawkrKZ7hdD5DetwWzvdcdPsgmmQpxs6OdSKds\/widgetDOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/d2oc6krkhhy4rsDOTcloudfrontDOTnet\/scripts\/script-marjory-warren-boutique-1657538629DOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/seoDOTappsDOTavadaDOTio\/scripttag\/avada-seo-installedDOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/cdn1DOTavadaDOTio\/flying-pages\/moduleDOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/assetsDOTgivzDOTcom\/widgets\/shopify\/pre-purchase\/latest\/givzDOTminDOTjs?shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/pop-convert-scriptDOTnetlifyDOTapp\/productionDOTpcDOTminDOTjs?unique_id=marjory-warren-boutiqueDOTmyshopifyDOTcom\u0026shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","","","","","","","https:\/\/toolsDOTluckyorangeDOTcom\/core\/loDOTjs?site-id=d0ab7806\u0026shop=marjory-warren-boutiqueDOTmyshopifyDOTcom","https:\/\/cdnDOTshopifyDOTcom\/shopifycloud\/shopify_chat\/storefront\/shopifyChatV1DOTjs?api_env=production\u0026button_color=%23f47048\u0026button_style=text\u0026i=chat_bubble\u0026p=bottom_right\u0026shop_id=XULLZSoJjgnpaZ4dKjQGM_PuF_nV5t37PsioUYLALCo\u0026t=chat_with_us\u0026shop=marjory-warren-boutiqueDOTmyshopifyDOTcom"];
    for (var i = 0; i < urls.length; i++) {
      var s = document.createElement('script');
      if (lightJsExclude.indexOf(urls[i]) === -1) s.type = 'lightJs'; else 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);
  }
})();

 

Built more than 10 public Shopify apps for clients, with partners and our own – https://asoft.co
Appifiny
Shopify Partner
165 2 54

Same issue. I've noticed that the Async code is different between merchants stores.

I don't know if it's an app that is causing the different code to be used, the theme (maybe a difference between legacy and OS2 themes?), or the age of the Shopify account?

As this post was in July and it is now October, it doesn't seem like they @KB77  have found the cause yet.

Below are the two different versions of AsyncLoad in two different merchants stores with script tag URL's removed.


Broken Async Load:

<script>(function() {
  function asyncLoad() {
    var urls = [""];
    for (var i = 0; i < urls.length; i++) {
      var s = document.createElement('script');
      if (lightJsExclude.indexOf(urls[i]) === -1) s.type = 'lightJs'; else 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);
  }
})();</script>

 

Working Async Load

<script>(function() {
  function asyncLoad() {
    var urls = [""];
    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);
  }
})();</script>

 

Try the best recent order app for Shopify free for 7 days: https://apps.shopify.com/recently
Zoltan8D
Visitor
1 0 1

I have problem with this Disco Flash app and their support said its not their app actually, its some bigger problem.

This was their answer. "Hi again I found the error. Something in your theme was actively refusing all app scripts to load. I specifically added an exception for our app, but all other apps are still being refused to load. If I were you, I would ask my theme developer to look into it. Hint: search in your source code for lightJsExclude. "

So can someone explain to me whats problem here and how we can fix it? I guess thats Shopify problem. I found this topic, do u think its same problem and how can fix it? 


SophieJupiter
Visitor
1 0 1

Hi,

 

I solved the issue by deleting the AVADA SEO Suite from the head of my theme.liquid.

 

Hope this helps.

axis80
Shopify Expert
23 1 9

One of my app customers is having a similar problem on their store, and I'm very grateful to have found some answers in this thread.  On my customer's store the circumstances are slightly different from what others have described here. The Avada SEO Suite app is still installed, and lightJsExclude is defined in theme.liquid.  My app is loading about 2/3 of the time and failing to load the other 1/3 of the time.  I'm not clear on the reason for that - perhaps it is loading different versions of some script in round-robin order from different servers.

 

It appears there are a couple features within Avada SEO Suite that could interfere with other scripts. First, it has a feature called Script Manager which can be used to enable/disable other scripts in use on the store.  That is described here: https://help.avada.app/script-manager/

 

Second, when the Minification feature is enabled, it appears that they download all script assets on the page, minify them, and then reupload them to Shopify's CDN.  They then wrap the entire theme.liquid template with Liquid {% capture %}{% endcapture %} tags, and that rewrites the HTML output sent to the browser so that it serves the assets as a single bundle.  Or something like that.  I find both of these "features" highly dubious and I wonder if Shopify would even allow this if they knew about it.

I created a copy of my customer's live theme for testing purposes, and manually removed the Avada SEO Suite using the instructions here.  My app is now loading consistently in that test theme and it appears the problem is solved.