当前位置:网站首页>Browser rendering principle analysis suggestions collection
Browser rendering principle analysis suggestions collection
2022-07-27 19:08:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
Web Pages run in all kinds of browsers , Browser load 、 The speed of rendering a page directly affects the user experience , Page rendering means that the browser will html The code is based on CSS The defined rules are displayed in the browser window . Let's first get a general idea of how browsers work : 1. User input web address ( Suppose it's a html page , And for the first time ), The browser makes a request to the server , Server return html file ; 2. Browser starts loading html Code , Find out <head> There is a... In the label <link> Tag references external CSS file ; 3. The browser sends out CSS File request , The server returns this CSS file ; 4. The browser continues to load html in <body> Part of the code , also CSS The documents are in hand , You can start rendering the page ; 5. The browser found a... In the code <img> The tag quotes a picture , Make a request to the server . The browser will not wait for the picture to download , Instead, continue to render the following code ; 6. The server returns the image file , Because the picture takes up a certain area , It affects the arrangement of the following paragraphs , So the browser needs to go back and re render this part of the code ; 7. The browser found a line containing Javascript Code <script> label , Run it quickly ; 8. Javascript The script executed the statement , It commands the browser to hide one of the code <div> (style.display=”none”). Cup set , All of a sudden, there is no such element , The browser has to re render this part of the code ; 9. Finally, here we are. </html> The arrival of the , The browser is full of tears …… 10. wait , It's not over yet. , The user clicks “ Skin peeler ” Button ,Javascript Let the browser change <link> Labeled CSS route ; 11. The browser brings together all of you <div><span><ul><li> People ,“ Pack up, guys , I have to go back to ……”, The browser asks the server Asked for a new CSS file , Re render the page .
Why is the page slow ? That's because browsers take time 、 Take the effort to render , Especially when it finds that there's a little change in a part that affects the layout , Need to go back To render , Experts call this retreat process reflow.
reflow The problem can be optimized , We can minimize unnecessary reflow. For example, in the example at the beginning <img> Image loading problem , This is actually an avoidable reflow—— Just set the width and height of the picture . In this way, the browser will know the footprint of the image , The position is reserved before loading the image .
in addition , There is a sum reflow Terms that look similar :repaint, It is called redrawing in Chinese . If you just change the background color of an element 、 writing Word color 、 Border color and so on do not affect the properties of its surrounding or internal layout , Will only cause the browser repaint.repaint It's obviously faster than reflow( stay IE I need to change my words ,reflow than repaint More slowly ).
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/120702.html Link to the original text :https://javaforall.cn
边栏推荐
- WPS turns off annoying advertisements
- JMeter interface automation - how to solve the content type conflict of request headers
- The great idea of NS2
- Code interview of Amazon
- NPM, cnpm Taobao image
- Product recommendation and classified product recommendation
- express get/post/delete...请求
- C static method and non static method
- Household mute mosquito repellent lamp chip-dltap703sd-jericho
- Latex use - subfigure vertical graphics
猜你喜欢

Unity learning notes (rigid body physics collider trigger)

Express get/post/delete... Request

汇编语言入门基础(1)

The understanding of string in C.

Redis annotation

Netred RGB mirror light touch chip-dlt8s15b-jericho

JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)

How to break the team with automated testing

web UI 自动化测试:Selenium 语法详解 史上最全

阿里云对象存储OSS的开通和使用
随机推荐
又有一个Repeater的例子
Product recommendation and classified product recommendation
Music rhythm colorful gradient lamp chip -- dlt8s04a- Jericho
电磁场学习笔记-矢量分析和场论基础
ES6数值的扩展
JMeter interface automation - how to solve the content type conflict of request headers
Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
MySQL 03 advanced query (I)
功率单位(power control)
Express get/post/delete... Request
Resource for NS2 beginner
An experience
Kinect for unity3d - backgroundremovaldemo learning
贪心法,拟阵和亚模函数(refer)
Unity学习笔记(实现传送带)
自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据
Ruiji takeout SQL table
Latex使用-控制表格或者图形的显示位置
MicaZ+Tinyos学习笔记(1)
ES6学习笔记(1)——快速入门