The question sounds stupid, but I have this in my mind for period and I want some peace. Does the browser execute javascript function after a js file is fully loaded, or does it execute immediately after partially loaded. I ask this because I would design my script architecture accordingly, especially with the new ability of modern browser. Some functions can be executed immediately, and some functions have to execute later. I'm talking about mufti-thread, asynchronous javascript. Thank you,
In case you do not understand my question. I would use settimeout to run some functions almost immediately. I test it on my computer and it just works. In real life webpage are mostly takes more time to fully loaded. When the function I mentioned executed, the other would stop or set to null and cannot be reused.
if you are using Jquery you can simply wrap your javascript content with $(document).ready(.... that way you make sure that everything "important" loads first and the page execution is done right. more over you can use a jquery plugin-in that make sure images are loaded as well before doing anything else. Now as for you question i am pretty sure that the header file loading starts before everything else however if the file is too big and you try to perform something that required function or components within that file that haven't been loaded yet. you'll have a problem
JavaScript execution order can be a bit confusing, particularly since it varies from browser to browser depending on how they tried to optimize it -- but really in terms of your question it should make no difference -- just assume that execution will not start until loading is finished. It's the safest assumption given that JS behaves that way even when it isn't running that way, which is why you can have out-of-order declarations (something languages like C++ or Object Pascal won't even let you past the compiler with) That said, it sounds like you're using flawed/outdated methodologies since things like document.write or innerHTML are slow, force reflows, and in general result in bloated code. The same goes for the various onevent attributes for HTML tags -- they have no place in modern markup. The method I advocate involves putting ALL my scripts right before </body> and having the scripts attach themselves to the markup by walking the DOM. In other words, how we've been told to do it for a decade given how it's better performing and usually less code. But of course with people crapping all over websites with bloated slow idiocy like jQuery, Prototype, etc, etc... hardly a shock outdated/broken methodologies continue to be all the fashion. If 1990's style garbage can be popular on the markup side with people still sleazing out HTML 3.2 and slapping 4 tranny or 5 lip-service on it, having the same type of bad practices in scripting as the norm should be expected. But to be fair, I'm one of the nutters who now writes with "use strict" so... In any case, if you're using document.write or onevent in your markup, or innerHTML in your scripting -- you're probably doing something wrong! (like manipulating data from your scripting pissing all over your accessibility)
Is it safe to assume you do not like jQuery ? Well what other alternative are there that would be such extensive upgrade from pure JS and would still operate the same as jquery?
90%+ of what jQuery does or people do with it is crap that either doesn't belong on a website or is CSS' job! Goofy "gee ain't it neat" animated garbage that does nothing but waste bandwidth and get in the way of using websites, inaccessible broken image rotator/slider crapping you into a fixed width layout, AJAXing in content to emulate the old frameset behaviors pissing all over accessibility, etc, etc... ... as to anything USEFUL done with jQuery, usually I can code the same or even smaller WITHOUT it using "pure js" without any stupid malfing 'framework'... Though my list of 'useful' on a website for scripting is really small since I actually practice bandwidth and file count limits; my ideal target being 72k in 8 files for a content-less template, 144k in 24 files my acceptable upper limit for an entire page.... and that's for HTML + CSS + IMAGES + SCRIPTS! Hell, I still say that for the majority of normal websites if you need more than 16k of UNCOMPRESSED scripting, you're doing something wrong... and for something that "needs" more scripting like a forums, I would only double that number... which BARELY puts you at the size of jQuery COMPRESSED. But again, I also maintain that if you can't make a page that works without JavaScript first, you have no business adding JavaScript in the first place! For MOST websites scripting should be used with an eyedropper to ENHANCE a page's functionality -- and most people using it these days seem to crap all over accessibility by using it to supplant it, crap all over page-load times using megabytes of scripting for **** only knows what, and on the whole resulting in code to content ratios of over 100:1 by the time you figure in all the scripting. See 90% of the pages people ask help for or for reviews of on these forums, where you see the sheer idiocy of wasting megabytes of scripting, CSS and markup in dozens of files on delivering single digit K worth of plaintext and maybe a dozen actual content images. (going hand in hand with the trifect of /FAIL/ at accessibility of fixed width layouts, fixed metric fonts, and illegible color contrasts). See part 3 of my article on a friends forum for more http://techtalkin.com/Thread-So-what-s-wrong-with-your-website-PART-3
So what you are saying is that there is no substitute nor alternative to achieve what jquery do in the amount of lines they do it and how simple it is for most users at the size of their plugin. Ofc you can use pure JS which will make the site lighter but that would be time costly and would require HELL more lines of codes therefore cost the average developer more money or time. Now considering most of the big website including google facebook etc... are using plugins that are the same or very close to Jquery, i think its safe to assume that for the normal user jquery is a good choice and and a tool that would make her or his live a lot easier.
No, I'm saying for anything useful it would be the same amount of code or possibly even less code without it if you have ANY clue what you are doing -- especially if you have ANY clue how to use CSS where much of the crap people do with jQ would be easier done with a simple regex on .className. Anything else is crap that has no malfing business on a website in the first place, making jQuery nothing more than bloat, making code HARDER to follow due to it being needlessly and pointlessly cryptic, and in general pissing away anything remotely resembling accessibility, graceful degradation, or sane use of scripting on websites. This means: Is absolute nonsense -- though it is the wild sensationalist BS claim you get from script-tards all the time. How is NOT wasting time on crap that has no business on websites harder? How is using less code 'harder' or 'hell more lines'??? Serious whiskey-tango-foxtrot territory. ... and just because all the other lemmings are running off a cliff by pissing away anything remotely resembling accessibility... and in some cases (like google) crapping away everything that let them bury their competition in the first place, and instead trying to become the next "Ask Jeeves" by doing all the things that buried that company... Of course that CSS3 transitions makes 60%+ of jquery's codebase obsolete...