Simple question. If you include jQuery in a page of HTML, is there any initialization overhead before one uses any jQuery functions.
Yes, a tiny bit. On my very fast machine, it seems to delay the page load by about 4ms.
jQuery itself doesn't really do much to speak of at load time, but naturally downloading the script, parsing it and executing the inline code to define all its functions takes a little while. It's unlikely to be terribly significant in itself on a normal desktop browser.
By virtue of simply including the jQuery script, you do indeed get some overhead. jQuery builds itself up inside an immediately executed function.
In 1.3.2 the biggest things it does are for IE support:
- creates a temporary
formelement with oneinputelement inside it, to check to see if the browser returns elements by name when querying bygetElementById- [Source] - creates a temporary
divwith a emptycommentnode in it, to check to see if the browser returns only elements when doinggetElementsByTagName("*")- [Source] - creates a temporary anchor element, to see if
getAttributereturns normalizedhrefattributes - [Source] creates a temporary
divwith this html in it:' <link/><table></table><a href="/a" style="color:red;float:left;opacity:.5;">a</a><select><option>text</option></select><object><param/></object>'and proceeds to read off a bunch of characteristics from that structure. This is to build the
jQuery.supportobject that was created in lieu of deprecatingjQuery.browser- [Source]
It also does some smaller things like:
- creates a whole whack of regular expression objects
- parses
navigator.userAgentfor some deprecated browser sniffing support - gets the current Date from the system (
+new Date)
Keep in mind all this barely adds up to any noticeable lag, as others have suggested.