1

I have a html page which load 10 js files from server and 10 css files from server. First JS file contain jquery ready function.

$(document).ready(function(){
alert("Executed");
});

My question is when ready function will be executed ? Is it just after html is loaded(i believe loaded means HTML is rendered on browser here ) or all(HTML + JS + CSS) files loaded?

Also per mine understanding all JS/css file loading is asynchronous (i mean parallel multiple requests are made to load these files). Right ?

emilly
  • 10,060
  • 33
  • 97
  • 172
  • @Rory McCrossan Link does not answer mine question. It discussed about CSS only but mine question is both about JS and CSS. Please reopen this as its not duplicate – emilly Oct 05 '16 at 13:13
  • Try [this one](http://stackoverflow.com/questions/2397534/how-soon-will-jquerydocument-ready-be-called). This has been asked a lot. Basically document.ready fires when `DOMContentLoaded` fires, which *can* be before all script and CSS files have been loaded, but very rarely does – Rory McCrossan Oct 05 '16 at 13:15
  • @RoryMcCrossan Accepted Answer seems confusing to me as it says ready will be executed only after all JS files are loaded . On the other hand it also says` in most cases, the script can be run as soon as the DOM hierarchy has been fully constructed.` As construction of dom hierarchy does not include loading js file, answer seems contradictory to me, – emilly Oct 05 '16 at 13:44
  • Can you please reopen this question for answers as any of these links does not answer mine question – emilly Oct 05 '16 at 13:46
  • 1
    document.ready is fired when DOMContentLoaded fires. The DOMContentLoaded event is fired when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.Also javascript should has been loaded and executed(inline scripts). See https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded – emilly Oct 05 '16 at 18:38
  • @RoryMcCrossan DOMContentLoaded is fired only after all scripts are loaded (but yes before CSS is loaded as its asynch process). See http://stackoverflow.com/questions/34269416/when-does-parsing-html-dom-tree-happen and https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded – emilly Oct 05 '16 at 18:40
  • another related link is http://stackoverflow.com/questions/1072774/what-is-speculative-parsing – emilly Oct 05 '16 at 18:50
  • Discusses when jQuery ready fires: https://learn.jquery.com/about-jquery/how-jquery-works/ and http://api.jquery.com/ready/ – Jeremy Ray Brown Dec 30 '16 at 18:36
  • browser support for DomContentLoaded: http://caniuse.com/#search=DOMContentLoaded – Jeremy Ray Brown Dec 30 '16 at 18:43

0 Answers0