Check out the code you wrote before. There are many codes like this:
$(function(){
//do something.
});
You may write some initialization styles, attach event processing to other DOM elements, etc. No problem was found at first, but when the page referenced some slow-downloading images, a problem arose: between the time the page HTML was downloaded and all resources were downloaded, the events bound to the DOM element could not be executed. Chaotic situations such as invalid styles bound by scripts, that is, whether ready is executed.
Ok, my situation is quite special. Maybe this situation is impossible for most students to encounter, but during development we have to consider that in some worse situation, a user opens Your website, and then you happen to have a lot of images on your page. . . Then he can only wait. . .
Solution: Return to basics
Before ready appeared, our writing method might be like this:
Insert a script block in the document
hello world
Such code is loaded here in the browser will be executed. Note that if the DOM element test1 here is after the script block, an exception will occur here.
I just need to execute these codes when the page is loaded. I don’t need all the resources of the page to be loaded, so there is no need for me to sit here and wait for the "slow" ready.
Well, think about it and sort out the html structure.
It’s not good to have script blocks everywhere on the page, which is not conducive to reading. So just sort them out and drag them to the end of the document.
//Let’s put some fancy stuff like title, meta, link, etc. here.
Body html…….
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31