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

  • SEARCH
  • Home
  • 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 8331443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:25:10+00:00 2026-06-09T02:25:10+00:00

If JQuery calls elements that don’t exist, what is the overhead for this? It

  • 0

If JQuery calls elements that don’t exist, what is the overhead for this? It throws no errors, but other than loading the script is there much cpu overhead? Does it matter if this is done for a class or an id?

For caching reasons and reasons of keeping simultaneous connections at a minimum I keep all my onload scripts for every page in one file, but I was wondering if it would be efficient or not to tell my javascript which page it is on and load only the bits of code that would be actually ran on that page via if statements or switch statements. I don’t want to put them in seperate files as I want every page to load as much from cache as possible after the initial visit.

Example you are on the home page, but have product page javascript included in that file or onload.

$('#product_options').hover(function(){},function(){});

But product_options doesn’t exist on this page because it’s the home page.

And does it make a difference for classes such as

$('.addtocart').click(function(){})

It should be noted this doesn’t throw any errors in JQuery.

  • 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-06-09T02:25:12+00:00Added an answer on June 9, 2026 at 2:25 am

    jQuery has a special “fast” path to process single id selectors such as #product_options; all other selectors are handled in a much more involved manner. If you keep to id selectors the performance impact is going to be non-measurable.

    If you use other selectors then the performance hit will be relatively much greater but in absolute terms it isn’t likely to have much impact unless we ‘re talking about dozens of selectors.

    However, you can sidestep all this by putting your code inside functions and then from each page call only those that are relevant. It isn’t too much to write in each page

    <script type="text/javascript">
    $(function() {
        doSomething();
        doSomethingElse();
    });
    </script>
    

    IMHO this is a nice balance between not dispersing your code across many files while at the same time also not attempting to run dead code.

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

Sidebar

Related Questions

I have a div <div id=customFormContact> .. other elements that don't matter ... <input
I am making jquery calls to get and getJSON, but cannot access returned values
I have the following jQuery calls chain: $(someSelector).nextUntil(.specialClass).addClass(classBasedSomeSelectorObject) I need to addClass that's value
As jquery ajax calls makes life really cool without a page refresh... But still
basically I have a function that resizes elements accordingly with jquery triggering the function
I have a jQuery AJAX data grid that loads a list of elements from
I really don't know how to express this question. But what I'm trying to
With most jQuery function calls that change the selection, it is possible to go
I am a bit lost. Maybe it's that I don't understand jQuery that well
this might be a stupid question, but I'm using asp.net list control that creates

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.