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 8076143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:12:04+00:00 2026-06-05T15:12:04+00:00

I do a little bit of third party javascript work for a company where

  • 0

I do a little bit of third party javascript work for a company where I am able to enter my javascript snippets into the CMS and have it run in the customer facing sites.
I have the option to switch on JQuery 1.7.1 in the header of the site and I usually choose to do this or not depending on how much more complicated it would make my code if I didn’t.

I have often wondered how much difference it would make if I just turned it on in all cases so even simple things like:

document.getElementById('myElement');

became

$('#myElement');

Where would the ‘breakpoint’ be in deciding it was better / more efficient / easier to switch on JQuery?

Today’s example that made me think of this was as follows (both regular javascript followed by the JQuery equivalent ):

Javascript:

if (document.getElementById('myElement')!== null) {
    var oldText = document.getElementById('myElement').innerHTML,
    newText = oldText.replace(/one/i,'two');
    document.getElementById('myElement').innerHTML = newText;
}

jQuery:

if ($('#myElement').length !== 0) {
    var oldText = $('#myElement').html(),
    newText = oldText.replace('one','two');
    $('#myElement').html(newText);
}

And How much is the negative affect on forcing the clients to download 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-05T15:12:06+00:00Added an answer on June 5, 2026 at 3:12 pm

    The difference will be minimal, and not worth writing those 10 chars…

    As always, remember that as a developer, your time is typically the most valuable resource. Do not focus on optimization of selector speed unless it is clear that performance needs to be improved.

    jQuery site

    And of course jQuery has a lot more features than id selectors…


    A good advise is to cache the queried elements and not query them multiple times, but it’s true both with jQuery and with vanilla javascript;

    From:

    document.getElementBy('id').value = "foo";
    document.getElementBy('id').parentNode.className = "parent";
    

    To:

    var element = document.getElementBy('id')
    element.value = "foo";
    element.parentNode.className = "parent"
    

    or jQuery version:

    var $element = $('#id');
    $element.val("foo");
    $element.parent().addClass("parent");
    

    Due to jQuery "chainabilty" – cascading styile, you do that with one "chain":

    $('#id').val("foo").parent().addClass("parent");
    

    This jsperf shows that $('#id') is 3-6 slower than document.getElementById
    Which means you can have "only" 1,000,000 those operations per second… "A disaster"!

    "We should forget about small efficiencies, say about 97% of the time: premature 
    optimization is the root of all evil"


    Regarding to the "loading"- downloading time of the jQuery library.

    • The current minified version of jQuery (1.7.2) size is only 32K, which is almost for sure smaller than most of images in your website, so it’s negligible.
    • You can use google global cached copy of jQuery, read more about it in this long blog post.

    No matter how well optimized your site is, if you’re hosting jQuery locally then your users must download it at least once. Each of your users probably already has dozens of identical copies of jQuery in their browser’s cache, but those copies of jQuery are ignored when they visit your site.

    However, when a browser sees references to CDN-hosted copies of jQuery, it understands that all of those references do refer to the exact same file. With all of these CDN references point to exactly the same URLs, the browser can trust that those files truly are identical and won’t waste time re-requesting the file if it’s already cached. Thus, the browser is able to use a single copy that’s cached on-disk, regardless of which site the CDN references appear on.

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

Sidebar

Related Questions

I am consuming JSON data from a third party API, doing a little bit
I have little bit longer question for you - but hope answer will be
I have been researching various third party libraries and approaches to low latency serial
Little bit of background, I'm more experienced with Java, and have some C/C++ experience.
I'm trying to understand ReST and XML a little more - A third party
I have a little bit of confusion about iOS Apps publication. The first time
This little bit of syntax has been a bit of a confusion for me
I am a little bit puzzled as to how I can optimize my program
I am little bit confuse about log4j in grails. I need to log info
I only read a little bit about this topic, but it seems that the

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.