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

147
Views
is it better to use javascript or css to swap out elements on screen size change for performance speed and less bugs

is ti better to use javascript, checking the window.innerwidth.

or is it better to have the display:none on media query

in terms of both lack of bugs and performance speed for simple situations.

for example:

you could either make a hook, or function that looks at the screen as ti changes or you could have a media query setting one to block and one to display none.

which one is faster and which one is less buggy?

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

0

In the case of check screen size and manipulate the style it's better using only CSS.

If you want to check the window width in JS you have to use something like a resize event attached to the window/document. And even if you wrap it in a debounce function it cost expensive calculations.

Also, there's the possibility that a user can have JavaScript disabled and your code didn't work at all.

If for some reasons (edit the content or functionality) you have to use JavaScript the better way is to use window.matchMedia() instead of the innerWidth function inside a resize event

Here more about it: https://webdevetc.com/blog/matchmedia-events-for-window-resizes/#windowmatchmedia-to-the-rescue

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!