Browser kernel understanding
- It mainly consists of two parts:
Rendering engine
,Js engine
Rendering engine:
Responsible for getting the content of the page (HTML CSS IMG…) , and calculate how the web page will be displayed, and then output to a monitor or printer. Browser kernels interpret the syntax of web pages differently, so the rendering effect is also differentJs engines:
Parse and execute javascript to achieve dynamic web pages- At the beginning, there was no clear distinction between rendering engine and JS engine. Later, JS engine became more and more independent, and the kernel tended to only value rendering engine
IE : trident
The kernelFirefox: gecko
The kernelSafari : webkit
The kernelOpera
: used to bepresto
The kernel,Opera
Now switch toGoogle - Chrome
的Blink
The kernelChrome:Blink
(based onwebkit
,Google and Opera Software
Joint development)
HTTP request scenario
Get
Method: Get data usually (view data)- viewPOST
Method: Submit data to the server usually (create data)-createPUT
Method: Submit data to the server usually (update data)-update, withPOST
It’s a very similar approach, it’s submitting data, butPUT
Specifies the location of resources on the server, often used to modify dataHEAD
Method: Request only the header information of the pageDELETE
Method: Delete the resource on the serverOPTIONS
Method: Used to get the currentURL
Supported request modesTRACE
Method: Used to activate a remote application-layer request message loopCONNECT
Method: Convert the request link to transparentTCP/IP
The passage of
The HTTP status code
1XX
: Indicates the information status code100 continue
In general, when sending a POST request, the server will return this information after the HTTP header has been sent, indicating confirmation, and then send specific parameter information
2XX
: Indicates the success status code200 ok
Normal return message201 created
The request succeeds and the server creates a new resource202 accepted
The server has received the request but has not yet processed it
3XX
: redirect301 move per
The requested web page has been permanently redirected302 found
Temporary redirection303 see other
Temporarily flush redirects and always request new urls using GET304 not modified
The requested page has not been modified since the last request
4XX
: Client error400 bad request
The server does not understand the format of the request, and the client should not attempt to initiate the request again with the same content401 unauthorized
Request not authorized403 forbidden
Blocking access
404 not found
Can’t find a resource that matches the URL5XX
: Server error500 internal server error
The most common server-side errors503 service unacailable
The server is temporarily unable to process requests (possibly overloaded live maintenance)
What happens when you enter the URL from the browser address bar?
Basic version
- 1. Browser based on request
URL
toDNS
Domain name resolution, find the realIP
To initiate a request to the server; - 2. The server returns data to the background and the browser receives the file
(HTML, JS, CSS, images, etc.)
; - 3. Browser to loaded resources
(HTML, JS, CSS, etc.)
Carry on the grammar analysis, establish the corresponding internal data structure(e.g. HTML DOM)
; - 4. Load the parsed resource file, render the page and finish.
A detailed version
- 1. Receive the message from the browser
url
To enable network request threads (this part can expand the browser mechanism and the relationship between processes and threads) - 2. Start the network thread until it emits a complete
HTTP
Requests (this section involves DNS queries,TCP/IP
Request, five layer Internet protocol stack, etc.) - 3. Received the request from the server to the corresponding background (this part may involve load balancing, security interception and internal processing of the background, etc.)
- 4. Backstage and front desk
HTTP
Interaction (this section includesHTTP
Header, response code, message structure,cookie
And so on knowledge, can mention the static resourcescookie
Optimization, as well as encoding decoding, e.ggzip
Compression, etc.) - 5. Separate cache issues
HTTP
Cache (this section includesHTTP cache header
.ETag, catchcontrol
Etc.) - 6. The browser receives the message
HTTP
Packet parsing process (parsinghtml
– Lexical analysis and then parsing intodom
Tree, parsing,css
generatecss
Rule tree, merge intorender
The tree, and thenLayout, painting
Rendering, composition of composite layers,GPU
Drawing, processing of external chain resources,The loaded and DOMContentLoaded
Etc.) - 7.
CSS
Visual formatting model (rules for rendering elements, such as inclusion blocks, controller boxes,BFC
, IFC, etc.) - 8.
JS
Engine parsing process (JS
The interpretation stage, the preprocessing stage, the execution stage generates the execution context,VO
, scope chain, recycle mechanism, etc.) - 9. Others (can expand different knowledge modules, such as cross-domain,
web
Security,hybrid
Patterns, etc.)
Detailed Upgrade version
- 1. Enter a value in the address box of the browser
URL
- 2. Check the cache. If the requested resource is in the cache and fresh, go to transcoding
- 2.1 If the resource is not cached, initiate a new request
- 2.2 If it is cached, check whether it is fresh enough and provide it to the client directly. Otherwise, verify with the server.
- 2.3 There are usually two tests for freshness
HTTP
Head controlExpires
和Cache-Control
:- 2.3.1
HTTP1.0
provideExpires
, the value is an absolute time to indicate the cache fresh date - 2.3.2
HTTP1.1
increasedCache-Control: max-age=
, the value is the maximum fresh time in seconds
- 2.3.1
- 3. Browser parsing
URL
Get protocol, host, port,path
- 4. Browser assemble one
HTTP (GET)
The request message - 5. The browser obtains the host
The IP address
, the process is as follows:- 5.1 Browser Cache
- 5.2 Local Cache
- 5.3 hosts file
- 5.4 Router Cache
- 5.5 ISP DNS Cache
- 5.6 Recursive DNS Query (Inconsistent IP Addresses May Occur Due to Load Balancing)
- 6. Open one
socket
With the targetThe IP address
, the port establishes a TCP connection.Three-way handshake
As follows:- 6.1 The Client Sends a Packet
TCP SYN=1, Seq=X
Package to the server port - 6.2 Server Send Back
The SYN = 1, ACK = x + 1, Seq = Y
The corresponding package - 6.3 Client Sending
ACK = Y + 1, Seq = z
- 6.1 The Client Sends a Packet
- 7.
TCP
Send after the link is establishedHTTP
request - 8. The server receives the request after parsing, will forward the request to the server program, such as virtual host use
HTTP Host
The header determines the requested server - 9. Check the server
HTTP
Whether the request header contains the cache validation information, if the validation cache is fresh, return the corresponding status of 304, etc - 10. Develop reasonable procedures to read the complete request and prepare it
HTTP
Accordingly, operations such as database queries may be required - 11. The server forwards the packet
TCP
The link is sent back to the browser - 12. The browser receives the message
HTTP
And then turn it off as appropriateTCP
The four-way handshake to close a TCP connection is as follows:- 12.1 Sending by the Active Party
Fin=1,ACK=z,Seq=x
message - 12.2 Passive Sending
ACK=X+1,Seq=Y
message - 12.3 Passive Sending
Fin=1,ACK=X,Seq=Y
message - 12.4 Sending by the Active Party
ACK=Y,Seq=x
message
- 12.1 Sending by the Active Party
- 13. The browser checks the corresponding status code
- 14. If the resource is cacheable, cache it
- 15. Decode the corresponding
- 16. Decide what to do according to the resource type
- Analytical 17.
HTML
Documentation, buildDOM
Tree, download resources, buildCSSOM
Tree, execute JS scripts, these operations in strict order each month - Build a DOM tree:
- 18.1 Tokenizing: Parsing character streams into tags according to the HTML specification
- 18.2 Lexing: Lexical analysis converts tags into objects and defines attributes and rules
- 18.3 DOM Construction: Organize objects into DOM trees based on HTML tag relationships
- 19. When encountering images, stylesheets and JS files during parsing, start downloading
- 20. Build
CSSOM
Tree:- 20.1
Tokenizing
: character stream is converted to tag stream - 20.2
Node
: Creates nodes based on tags - 20.3
CSSOM
: the node creates the CSSOM tree
- 20.1
-
- According to the
DOM tree and CSSOM tree
Building a Render tree
- 21.1 from
The DOM tree
, traverses all visible nodes, invisible nodes include: 1)script , meta
So the tag itself is not visible. 2) Nodes hidden by CSS, such as display: None - 21.2 For each visible node, find the appropriate
CSSOM
Rule and apply - 21.3 Publish the content and computing styles of visual nodes
- According to the
- 22. Js parsing is as follows
- 22.1 Creating a Browser
The Document object
And parseHTML
, add the parsed elements and text nodes to the documentDocument. The readystate is loading
- 22.2 HTML parser encountered no
Async and defer's script
, add them to the document, and then execute inline or external scripts. These scripts execute synchronously, and the parser pauses while the script is downloaded and executed. So it worksdocument.write()
Inserts text into the input stream. Synchronous scripts often simply define functions and register event handlers that can iterate and manipulate scripts and their previous document contents - 22.3 When the parser encounters Settings
Script for async property
Start downloading the script and continue parsing the document. The script is executed as soon as it is downloaded, but the parser does not stop for it to download. Do not use asynchronous scriptsdocument.write()
They have access to their script and previous document elements - 22.4 When the document is parsed,
Document. ReadState into interactive
- 22.5 all
Defer the script
It is executed in the order in which it appears in the document. Deferred scripts have access to the entire document tree and are prohibiteddocument.write()
- 22.6 The browser is in
Document
Object on fireDOMContentLoaded event
- 22.7 At this point, when the document is fully parsed, the browser may still be waiting for content such as images to load and for all asynchronous scripts to load and execute.
Document. readState becomes complete, and the window fires the load event
- 22.1 Creating a Browser
- 23. Display the page (the page will be displayed gradually as the HTML is parsed)
Cookies, sessionStorage and localStorage
cookie
Data stored (usually encrypted) on a user’s local terminal by a web site to identify the usercookie
Data is always carried in the same HTTP request (even if it is not needed) and is passed back and forth between the browser and the server (optimization point)sessionStorage
和localStorage
Data is not automatically sent to the server and is stored locally- Storage size:
cookie
The data size cannot exceed 4KSessionStorage and localStorage
Although there is a storage size limit, it is much larger than cookies, reaching 5M or more
- Term time:
LocalStorage stores persistent data. Data is not lost after the browser is closed unless the data is deleted
SessionStorage data is automatically deleted after the current browser window is closed
Cookie The cookie set remains valid until the expiration time, even if the window or browser is closed
Browser cache
Browser caches are divided into strong cache and negotiated cache. When a client requests a resource, the process for obtaining the cache is as follows
- Let’s start with some of this resource
http header
Determine whether it matches the strong cache. If it matches, the cache resources are directly obtained from the local server without sending requests to the server. - When the strong cache does not hit, the client sends a request to the server, and the server sends a request through another
request header
Verify that the resource matches the negotiated cache, calledhttp
Then verify that, if a match is hit, the server will request back, but does not return the resource, but tells the client to directly get the resource from the cache, the client will get the resource from the cache after receiving the return; - Strong and negotiated caches have in common that the server does not return the resource if the cache is hit; The difference is that the strong cache does not send requests to the server, but the negotiated cache does.
- When the negotiation cache also dies, the server sends the resource back to the client.
- when
ctrl+f5
When the page is forced to refresh, it is loaded directly from the server, skipping the strong cache and negotiated cache. - when
f5
When the page is refreshed, the strong cache is skipped, but the negotiated cache is checked.
As a front-end developer for five years, I would like to share some experience from the perspective of the interviewer, hoping to help friends who want to go all the way to black in the front end:
What kind of resume will stand out?
1. Who am I?
Use a summary description to make a concise, clear and systematic review of your technical system, knowledge system, practical experience, and views on technology and learning. Before you write, ask yourself this question: “What are my thoughts and insights?” “The reason is simple. If all the candidates simply list the skills they know in their stack, and you can share your technical insights, you will stand out.
2. What did I do?
Each experience should be complete, including background, analysis and definition of problems, problem-solving ideas, practice process, problems and challenges, coping methods, highlights, summary and reflection. In the process of description, it is best to have specific data evidence, and in the process of analysis and judgment, it is best to have logical deduction. Before you write, ask yourself one question: “Why are these things different for me?”
3. My bonus?
Learn well, do more, produce more… Are all extra points, learn how to reflect? I think I can record my grades, achievements, competitions and papers. What about doing more? You can express your own study and research projects completely, as long as you can reflect your unique value, you can write out. At the same time, you should also pay attention to what you do in the industry to compare what level is it? No amount of writing can gain traction without unique value, and that’s when it comes to producing cattle. For example: business or user size? Traffic and usage duration, usage frequency? Github’s Star number, industry technology advancement and innovation value, etc.
4. Other content
Whether writing your resume or interviewing for a job, ask yourself: Why am I better than others? Summarize your best points and don’t let the interviewer guide you.
How can students improve their front-end skills?
1, learning,
Well as a student at the core is to learn, to learn very not equal to high scores, nature or whether you study to understand the content of the deep, whether to have their own independent opinions, if verified in practice these insights, whether based on iteration reflection practice again, correct their learning methods, learning process into the bottom and the nature.
2, practice
Only when there is enough depth in a system can more general technical ideas be summarized and refined, and the same goes for the front end.
First of all, don’t try to learn and understand all the popular frameworks, try to focus on one technical area of understanding. For example, one of my classmates was involved in a lot of front-end projects, from React to small programs, from the middle background to the front desk. But when we talked about it, we couldn’t grasp the principles and ideas behind technologies in any technical field.
Secondly, standard software engineering processes should be followed in practice: problem analysis and definition, technology selection, outline design, detailed design, research and development, debugging, testing, release and optimization. Want to exercise oneself to have good actual operation ability, want to start from good, standard operation method first.
Finally, in the application of technology to know the merits and demerits, have their own judgment to do the technology selection. Research and analyze solutions from top companies like FaceBook and Google, and learn the most advanced technologies like imgCook.com. Use your top problem analysis and definition skills, broad vision and technical sensitivity to find the best technology. Design and implementation will come naturally.
Write in the last
To the interviewer, the interview process is just a moment, your past and future are more important. Think about what problems you need to solve at work or in school, try different solutions, and summarize failures and successes. What matters most is what you want to be in the future, and work toward it.
For the interviewer, you need to find the good in each person, learn to appreciate each person, and in the process find a partner who is better than you.
Here is a 280 page PDF of the interview questions I compiled for the front-end school admissions, including HTML, CSS, JavaScript, React, Vue, browser, server and Network, algorithms, etc.