


JS/CSS/IMG loading order relationship DOMContentLoaded event_html/css_WEB-ITnose
Introduction to DOMContentLoaded
The triggering condition of the DOMContentLoaded event is:
will be executed after "all DOMs are loaded and JS is loaded and executed. trigger later".
But if "js is loaded dynamically, it will not affect the triggering time of DOMContentLoaded"
As shown in the figure below, the blue line means that DOMContentLoaded starts to trigger, but the premise is JS has been loaded and executed.
(It’s just the DOM, not the onload event that is triggered when the entire page is loaded. DOMContentLoaded is triggered earlier than onload, so please distinguish it. The red line on onload means that the page has been fully loaded)
What did IMG and CSS do before DOMContentLoaded was triggered?
As mentioned above, JS has been executed before DOMContentLoaded is triggered.
But what about IMG and CSS? Let's look at the picture below: The DOMContentLoaded event is triggered, but some pictures are blocked.
Blocking means that the browser delayed loading, although the image request was sent very early.
But the browser thinks that your CSS has not been loaded, and it is not sure what the style of the image is, which involves redrawing resources.
The image will then be loaded after the CSS is loaded. (There is no blocked image request in the picture below because there is no style name. Considering that CSS will not change it, the browser does not need to block it)
The key point is: although CSS Style sheets will block the loading of images, but: JS will not.
If your page does not have a CSS style sheet, all images will be loaded at the first time, and it will not be judged whether your JS has been loaded before loading the images.
This should be related to browser features. I am using firefox 29.01
Final conclusion
1. CSS style sheets affect images However, JS will not affect the loading speed. If you want the image to load as quickly as possible, do not use styles for the image. For example, just use label attributes for the width and height.
2. The loading execution speed of JS affects the triggering time of the DOMContentLoaded event. If you want to trigger the DOMContentLoaded event as soon as possible, load the secondary JS using dynamic loading.
Reference:
How does jquery’s ready function work? Introduced the difference between loading response events.
http://www.cnblogs.com/haogj/archive/2013/01/15/2861950.html
The impact of JS, CSS and img on the DOMContentLoaded event (this article uses The one is Chrome. I later tested it with Firefox and reorganized the knowledge. I would like to thank the author of this article! )
http://www.alloyteam.com/2014/03/effect-js- css-and-img-event-of-domcontentloaded/
Author: Margo_test
Source: http:// /www.cnblogs.com/margo/
Welcome to share and reprint.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics


![Error loading plugin in Illustrator [Fixed]](https://img.php.cn/upload/article/000/465/014/170831522770626.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
When launching Adobe Illustrator, does a message about an error loading the plug-in pop up? Some Illustrator users have encountered this error when opening the application. The message is followed by a list of problematic plugins. This error message indicates that there is a problem with the installed plug-in, but it may also be caused by other reasons such as a damaged Visual C++ DLL file or a damaged preference file. If you encounter this error, we will guide you in this article to fix the problem, so continue reading below. Error loading plug-in in Illustrator If you receive an "Error loading plug-in" error message when trying to launch Adobe Illustrator, you can use the following: As an administrator

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

Subtitles not working on Stremio on your Windows PC? Some Stremio users reported that subtitles were not displayed in the videos. Many users reported encountering an error message that said "Error loading subtitles." Here is the full error message that appears with this error: An error occurred while loading subtitles Failed to load subtitles: This could be a problem with the plugin you are using or your network. As the error message says, it could be your internet connection that is causing the error. So please check your network connection and make sure your internet is working properly. Apart from this, there could be other reasons behind this error, including conflicting subtitles add-on, unsupported subtitles for specific video content, and outdated Stremio app. like

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

On iPhones running iOS 16 or later, you can display upcoming calendar events directly on the lock screen. Read on to find out how it's done. Thanks to watch face complications, many Apple Watch users are used to being able to glance at their wrist to see the next upcoming calendar event. With the advent of iOS16 and lock screen widgets, you can view the same calendar event information directly on your iPhone without even unlocking the device. The Calendar Lock Screen widget comes in two flavors, allowing you to track the time of the next upcoming event, or use a larger widget that displays event names and their times. To start adding widgets, unlock your iPhone using Face ID or Touch ID, press and hold

If you encounter freezing issues when inserting hyperlinks into Outlook, it may be due to unstable network connections, old Outlook versions, interference from antivirus software, or add-in conflicts. These factors may cause Outlook to fail to handle hyperlink operations properly. Fix Outlook freezes when inserting hyperlinks Use the following fixes to fix Outlook freezes when inserting hyperlinks: Check installed add-ins Update Outlook Temporarily disable your antivirus software and then try creating a new user profile Fix Office apps Program Uninstall and reinstall Office Let’s get started. 1] Check the installed add-ins. It may be that an add-in installed in Outlook is causing the problem.

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese
