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?
Asked
Active
Viewed 218 times
0
-
4Don't put your JavaScript on those pages? – Brad Oct 12 '12 at 19:31
-
Some javascript slows down the pages? Wow.. trim that code down regardless! – TheZ Oct 12 '12 at 19:31
-
It's hard to answer this question without knowing how your javascript is being loaded to begin with – Trey Oct 12 '12 at 19:32
-
if your js code is running slowly, then the first thing to do is use a tool such as YSlow to find out *which* scripts are running slow, and why. – Spudley Oct 12 '12 at 19:33
-
Unfortunately the integration was built within x-cart so we have no control over where it loads. We used pingdom to determine that rpx.js (Janrain) is the javascript causing the slow loading times. – user1742192 Oct 12 '12 at 23:32
1 Answers
0
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
...

Nelson
- 49,283
- 8
- 68
- 81