The previous article about the CSI technology, which shows that the website of the static technology has been advanced to the browser end is really to the category of the Web front-end, and the forefront of the Web front-end technology is the front and rear separation technology, then the site static technology and front-end separation technology produced the intersection, So today I will discuss the next front and back end separation technology, after the end of the separation technology discussion, the next article I will be the site of static technology to revisit the perspective of the next front and back separation technology, I hope that through this review to deepen our understanding of the two sets of technology.
Front-end separation technology I personally think is the Web front end is specialization after the only way, and the emergence of Nodejs is a strong catalyst for the front and back end separation technology, because the emergence of nodejs flattened the front-end technology and service-side technology gap between the The two sets of different technology systems in the front and back end provide the infinite possibility of decoupling. But if we think that the use of NODEJS technology is to achieve the separation of the front and back, this understanding is too superficial, I will talk about my research on the front-end separation technology, and these technical solutions hidden behind thinking, I hope these thinking can give you a new way to understand the front-end separation technology.
We have a deep understanding of the front-end separation technology has an important premise, that is, the front-end separation technology is considered to be the traditional Web application of the MVC design pattern of further evolution. So we first look at the definition of MVC, the following excerpt from the Wikimedia Encyclopedia of the explanation, specifically as follows:
The MVC pattern (model-view-controller) is a software architecture model in software engineering, which divides the software system into three basic parts: model, view and controller.
?
The MVC pattern was first proposed by Trygve Reenskaug in 1978 [1] and was a software design model invented by Xerox PARC in the 1980s for programming language Smalltalk (Palo Alto). The purpose of the MVC pattern is to implement a dynamic program design that simplifies the subsequent modification and expansion of the program, and makes it possible to reuse a part of the program. In addition, this mode makes the program structure more intuitive by simplifying the complexity. The software system is separated by the basic parts of itself and also gives the functions of the basic parts. Professionals can be grouped by their own expertise:
?
(Controller controllers)-responsible for forwarding requests and processing requests.
?
(views view)-graphical interface design for interface designers.
?
(model)-Programmer to write the functions that the program should have (implementation algorithm, etc.), database experts for data Management and database design (can achieve specific functions).
All kinds of language for Web application development have their own MVC framework, for example, I am most familiar with the service-side language Java has the famous STRUTS2,SPRINGMVC MVC application framework, When I was early in Java Web Development I thought these MVC frameworks are very broad and extensive, but when I gradually turned to the Web front-end technology development and felt that many of these frameworks are so redundant and cumbersome, so I wrote an article specifically discussed these issues, The article's name is "Why do we do Java Web development using frameworks like STRUTS2,SPRINGMVC and spring?"
In fact, this article is written by the source is that I think like struts2 and springmvc such a framework does too many browser itself can do the work, such as: page rendering operations, because the server robbed the browser part of the work, which actually is tantamount to restricting the use of web front-end technology in depth, Like a lot of front-end optimization technology and a lot of technology to enhance the user experience is very difficult to come in handy, the reason for these problems, I think the traditional MVC framework is actually a service-side MVC framework, although the MVC design pattern of the V-view layer is to make the interface development work specialization, Allowing interface designers to focus on interface development, but the essence of the view layer under the traditional MVC framework is a service-side technology.
We take the Java Web Development JSP as an example, the full name of the JSP Java Server Pages, the Chinese name is the Java Servers page, which is a simplified servlet design, it is the Java Dynamic Web page technical standards, which shows that JSP, although it looks like HTML, In fact, it is not real HTML, it needs to be parsed by the Java Web container into an HTML page that can be parsed by the browser, and then transmitted over the network to the browser, the browser can correctly display the JSP page, other web development language has similar dynamic Web technology standards, But regardless of the language of the Dynamic Web technology standards, we use it when the Web front-end technology is kidnapped by the service-side technology, which is why every recruitment web front-end engineer to ask you whether you will java,php the source of the language. But with the development of the Internet, the requirements of the Web front-end is more and more specialized, the Web front-end itself contains the technical difficulty is no less than any one service-side language development difficulty, so we need a higher web front-end specialization, It does not want the Web front-end engineers to be constrained by the service-side technology more and limit the development of their own capabilities, which leads to the emergence of front-end separation technology.
However, the first phase of the front-end separation technology is not from changing the view layer that is the views layer, but from the connection between the client and the service side of the C layer is the control layer, the control layer both acting on the client and the service side, if a function page is a programmer from the browser side has been written to the model layer, Control layer is not a problem, but if we want to press the MVC design idea, let the interface developer focus on the page development, the service-side developers focus on the server development, then this time the control layer attribution problem is very important. In the traditional MVC framework, because the M layer and the C layer are using the same language system, it is natural for us to put the M-layer and C-layer development work to the service-side developers, this decision is understandable, But the traditional MVC framework in the V-layer and the C-layer is the same technical system (for example, Java Web Development JSP Essence is a servlet), so the V layer and the C layer is tightly coupled, so the interface developers to develop the page without C-layer support, Then this page is actually not run up, if the front-end developers at this time run to write C-layer control layer code, which broke the original horizontal division of labor, the control layer of the coding work will become chaotic and difficult to control, see here someone will say that since the control layer belongs to the service side, Then the front-end technical personnel and so on the development progress of the server, and then do not write a mock simulation under the control layer of the service, I believe that the front end or the service end of the technical staff will be the brain numbness, the first reaction is this is not asking for trouble, it is not as good as a person to complete. As a result of the first phase of the front-end separation technology, the solution is to solve the problem is how to enable Web front-end technicians and Web service technicians to work together, a reasonable division of labor, in other words, according to the Web front-end and Web server perspective can be horizontal decomposition of the web development work.
The first stage of the separation of the front and back ends is the problem of the ownership of the control layer, and from the technical point of view, whether the control layer should be decoupled from the views layer is reasonable or the decoupling with the model layer is more reasonable. So here we look at the definition of the control layer in the MVC design pattern, which is defined in Wikipedia:
(Controller controllers)-responsible for forwarding requests and processing requests.
??
But this explanation I think is not comprehensive, in Java Web Development in the design of the control layer as an example, we found that the control layer in the communication between the view layer and the model layer, the control layer in fact, the main completion of three specific tasks, which are:
Work one: The control layer acts as a route. After a client request arrives at the control layer, the control layer routes the request to a model layer on the server based on the requested content, and the model layer returns the response to the control layer after the request is processed, and the control layer is routed to a specific page based on the response information.
Work two: The control layer plays a role in the conversion of message information format. In Java Web Development, for example, the browser data are sent to the server in the form of HTTP messages, and the control layer is the HTTP message information to the Java object, of course, it can be the basic Java data type, and then the control layer of the parsed information passed to the model layer for processing.
Work three: In the traditional MVC framework, the control layer actually deeply involved in the page rendering operation. In the Java Web development of the control layer regardless of how to be packaged, its essence is a servlet, and the JSP page nature is a serlvet, so we can understand so jsp,jsp is to write Java in the way of page development, The servlet writes the page in Java, so we can output the page as a file stream in the servlet, or let the servlet jump to the JSP page.
From the above discussion, we found that the traditional MVC framework of the control layer and the model layer of contact is relatively simple, their connection is mainly the transformation of the Routing and Message format, and the control layer and the view layer of the connection in addition to a page rendering, and page rendering itself should belong to the technical category of the browser, Browser technology is an integral part of my above content is criticized the traditional MVC framework problems, if the control layer assumes the page rendering work, then the control layer and the view layer of the coupling becomes very high, it is very difficult to decouple it, generally only we break the existing MVC framework of the technical system to complete, In contrast, decoupling the control layer from the model layer becomes much easier. So how does the control layer decouple from the model layer? Specific as follows:
First of all, we solve the problem of the conversion of the message format, the technical solution is very simple to learn from the HTTP Unified message format, we define a unified message format for the control layer and the model layer, for example, we define the control layer and the model layer to the data type of the map data transmission, There is a dedicated field in this map to define the model interface information that is routed to, a field that is dedicated to storing the data that needs to be passed, and the design can be designed according to the actual business needs.
Next is the problem of routing, in the solution of the problem of the conversion of the message format, I said that in the unified message format to specifically define a field to store this data exactly what model to route to processing, but this field does not completely solve the routing problem, so we need the model layer to the control layer to provide a unified interface, Any control layer and model layer of communication through this unified interface to complete, but different request message assembly content is not the same, and this interface has an important responsibility is to parse the message in the routing information, so that the request can be correctly routed to the corresponding model interface processing. Of course, the return value of this interface is best also a unified message format, so that the control Layer parsing model layer return data will be more convenient.
From the above, we found that the first stage of the separation of the front and back of the work control layer should be attributed to the Web front-end, it is more reasonable and easier to implement, in fact, after the evolution version of the front-end separation scheme, control layer is also a web front-end, but the form is different, this I continue to discuss in the
The core of the first-stage and front-end separation solution is to decouple the control layer from the model layer, and this scheme evolves, we can separate the control layer and the view layer into a Web application, the model layer is independent into a Web application, and the two Web applications communicate through remote calls. As I wrote in the previous article, this article is called the distributed architecture of the Web site I designed.
This evolutionary version of the program increases the difficulty of system development because we need to increase the programming of network communications and the implementation of remote calls, and more troublesome is that we also need to carry out complex multithreaded programming, since the increase of the difficulty of development why should I do so? First of all, we can dynamically adjust the load pressure on the Web front end and Web service side through the application layering, but also can provide a security barrier before the model layer, but the Web front end kidnapped by the server is still very limited in lifting the entire Web application load capability. In fact, the greatest benefit of this approach is to facilitate the design of the SOA framework, which means that we can provide a strong guarantee for the SOA of the server, because the decoupling of the control layer and the model layer allows the model layer to truly focus on the business, The problem of writing business logic to the control layer will not happen again, thus reducing the robustness of the code.
Well, write it here today, best wish you a happy New Year, good night.
Thoughts on the evolution of large-scale website Technology (14)--Website static processing-front and back separation-upper (6)