Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6816559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:56:25+00:00 2026-05-26T20:56:25+00:00

I have some script similar to the following: var breakpoints = [0,240,480,960,9999], bpCount =

  • 0

I have some script similar to the following:

var breakpoints = [0,240,480,960,9999],
    bpCount = breakpoints.length,
    windowsize = 0;

window.onresize = function() {

    windowsize = document.body.clientWidth;

    for(var i=0; i<bpCount; i++) {
        if(windowsize >= breakpoints[i] && windowsize < breakpoints[i+1]) {
            doSomething(breakpoints[i]);
            break;
        }
    }    

};

However this seems to run pretty slowly, even in Chrome on a decent PC, and even when ‘doSomething’ is just performing a ‘console.log’, so I was just wondering if there was any better way of checking whether the screen size is between two values as it resizes?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:56:26+00:00Added an answer on May 26, 2026 at 8:56 pm

    Don’t poll for the size every single time. You’re using way too much computing power.

    Instead, make a timer and check for the size every so often (10 ms might be too fast):

    var checkWindowSizeTimer;
    
    function checkWindowSize() {
        var windowsize = document.body.clientWidth;
    
        if (windowsize >= breakpoints[i] && windowsize < breakpoints[i+1]) {
            doSomething(breakpoints[i]);
            clearInterval(checkWindowSizeTimer);
        }
    }
    
    window.onresize = function() {
      checkWindowSizeTimer = setInterval(checkWindowSize, 10);
    }
    

    When the window is resized past your bounds, the timer exits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure similar to the following: /root/ /root/data/ /root/data/script.php /root/data/some.json /root/data/feature/one.json /root/data/feature/two.json
I have some script that is delivering a series of rows from an SQL
I have some script in my default page that redirects users to language specific
Possible Duplicate: Is there any working memory profiler for Python3 I have some script
I have developed some script for detecting when user scroll down a page, and
I am writing some BASH script and I want it have some error handling
I have some boiler-plate script required for a Telerik RadGrid on one of my
I have some accent issues in a shopping cart script. Here's a part of
I have some Perl code that executes a shell script for multiple parameters, to
I have some status text displayed in a BASH script, e.g.: Removed file sandwich.txt.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.