Loading a script via JS code doesn't execute it on certain page, but works on other pages

32 views Asked by At

I am dynamically load a script, which when executed will expose a global prop on the window object. However, on our shopping cart page it doesn't work - I see the network request, it is successful - but that's it. No errors in the console so far.

I tried two ways:

  1. With jQuery's getScript method:
    $.getScript('https://cdn.jsdelivr.net/npm/bowser@latest/es5.js');
  1. With native JS:
    var bowserScript = document.createElement('script');
    bowserScript.src = 'https://cdn.jsdelivr.net/npm/bowser@latest/es5.js';
    document.body.appendChild(bowserScript);

And later, when user do something, under some condition I'm using window.bowser - which comes from this script.

This works on all pages except the shopping cart page. It is a single page app. It loads some React components, even though the SPA is not built with React.

So - any idea where the problem could come from? Some setting of the page, some meta tag ...? ... I've tried on other places, also tried to prepare fiddler - but it simply works everywhere else.

0

There are 0 answers