I want execute some javascript just when the dom and css is ready, but I don't care about the image(I'm tend to lazyload the image)
I know how to detect the dom ready status, but how to detect the css is ready?
When it comes to ordering your CSS and JavaScript, you want your CSS to come first. The reason is that the rendering thread has all the style information it needs to render the page. If the JavaScript includes come first, the JavaScript engine has to parse it all before continuing on to the next set of resources.
You can run javascript code at any time. AFAIK it is executed at the moment the browser reaches the <script> tag where it is in. But you cannot access elements that are not loaded yet.
ready() is a jQuery event which occurs when the HTML document has been fully loaded, while the window. onload event occurs later, when everything including images on the page loaded. Also window. onload is a pure javascript event in the DOM, while the $(document).
You should be using the document.ready
event. window.onLoad
fires when all the images and others are fully loaded.
Source: window.onload vs $(document).ready()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With