Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
How to find which js file creating problem

I have more than 20 js files like jQuery etc in my project, when I scroll it gets hung as it loads very lazily. How to find which file creates the problem?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

It may be one of several things and without looking at your code I couldn't possibly say what the cause would actually be. You've asked an extremely subjective comment. There's no silver bullet when it comes to debugging and problem solving.


I've always found the Occams Razor approach the most effective.

"When you remove all other options, whatever remains, however unlikely, must be the problem/solution/answer."


Firstly, before you start removing JS files, have you tried doing a full-search of your project for .scroll? There's a high likelihood that there are several functions which run on-scroll which are causing reflows, a common problem which such code.

Once you've assessed your code, you can verify exactly what happens when the code executes using the "Performance" tab in Google Chrome to do this (Learn how to use the Performance Tab here). You can take the appropriate action.


Assuming that your code suffers from the same problem I've encountered in my formative years using jQuery - multiple or problematic on-scroll events - you can de-bounce the ones which can run after scrolling has completed. You can do this by using the following pattern.

Scenario 1: This would run many times. 'N' times for each scrollwheel drag (dependent on settings - mine is 10) and even more times when using the scrollbar.

function someFunc() {
    let someArr = [];

    for(var i = 0; i < 1000000; i++ {
        someArr.push((i * 2));
    }
    
    for(var i = 0; i < someArr.length; i++ {
        someArr[i] /= 0.25;
    }
}


$(window).on("scroll", function() {
    someFunc();
});

Scenario 2:

This would run once after scrolling has finished. Waiting for 200ms before executing to ensure the user has completely finishing scrolling.

function someFunc() {
    let someArr = [];

    for(var i = 0; i < 1000000; i++ {
        someArr.push((i * 2));
    }
    
    for(var i = 0; i < someArr.length; i++ {
        someArr[i] /= 0.25;
    }
}

let debouncedTimeout = null;

$(window).on("scroll", function() {
    if (debouncedTimeout) {
        clearTimeout(debouncedTimeout);
    }

    debouncedTimeout = setTimeout(someFunc(), 200);
});
about 4 years ago · Juan Pablo Isaza Report

0

Add a console.log("Check") with numbers (check1, check2) and so on in every file. Check your console in your browser, look in which series they load in console. If it takes a while to load the next log you know its the previous file with the number you logged.

about 4 years ago · Juan Pablo Isaza Report

0

Your console should say everything. But loading so many js files is bad practice. Try to fit everything in to one, so in further bckend development can go to an .min.js But if you keep doing this. The simplest way is to keep track of the funcioncesequences with console.log, so that you evrything works how it is supposed to :)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!