How can I prevent a javascript code from loading on certain pages?

240 Views Asked by At

We use the e-commerce platform X-cart to host our shopping cart along with a built in integration for Janrain which allows for social login through facebook, etc. We wish to limit the ability to login to shopping cart pages as the .js code causes our site to load slowly on product pages. How do we prevent the .js code from running on product pages?

1

There are 1 best solutions below

0
On

Just put the following at the start of the javascript file causing slowness:

if (window.location.href.indexOf('/path/to/shopping/cart/pages') != -1) {
   //We are in shopping cart pages
   //and we don't this js file to cause slowness, so just exit
   return;
}
// rest of the js file
...