Web When applications are just emerging and replacing traditional client applications , The hot spot of technology is the server development language . from ASP,PHP reach Java,ASP.NET, No matter what technology is used , As the core of a system, business logic is written in a language running on the server side . Architects are used to dividing an application system into multiple layers , View layer , Business logic layer and data layer , And they're all in some kind of server-side programming language , combination html and sql Etc , Run on server .JavaScript As the language running in the browser , It's just used for verification , Scattered modification of the interface and other tasks . At that time, who would have proposed to write business logic in this auxiliary language , It's going to be a fantasy . But time goes by , technological development ,Web The system is more and more dependent JavaScript.JavaScript The ability and characteristics of language are thoroughly explored ,Ajax become Web Development routines ,JavaScript Frameworks emerge in endlessly and change with each passing day , More and more of the old arabian nights have come true . Take advantage of MVC Patterned JavaScript frame , The business logic code runs in the browser , adopt RESTful Services and servers exchange data , It's more and more functional , Gorgeous in appearance Web Technology path of application , To the extreme is the so-called single page application .
In this trend , An inevitable question is: should business logic really be moved from the server side to the browser side ?
benefit :
1.
Faster response .Web Most of the time spent by application system response is spent on network transmission . conventional Web Application whenever the business logic is to be executed , Even if it's a very simple calculation , All must be submitted to the server , Wait for the page to return . It was adopted later Ajax technology , The server can only return the data results after executing the business logic , The performance is greatly improved . Further , If the applied model data is transferred to the browser at the beginning , All the subsequent calculations are used JavaScript complete , Return to the server only when the database needs to be updated , Less network traffic , The system responds faster . and , Applications use temporary data that doesn't need to be persisted , For example, intermediate data related to interface display or calculation , The calculation of these data does not need to be transmitted to the browser on the server side . The combination of these factors makes Web In many cases, the response speed of application can reach the level of local application .
2.
Simpler structure . A function usually includes both invisible operations , It also includes changes to the user interface . If it's done in a traditional way , The server code calculates the business logic , Transfer results to browser ,JavaScript Revise again html Complete the changes on the display , Written in two languages , The encoding before sending data on server and decoding after receiving and sending data on browser also need special work . Transfer business logic to browser side JavaScript Writing makes the code more consistent , Simpler structure .
3. Better scalability . The code is distributed to each user's computer , Naturally reduces the load on the server .

Disadvantages :
1.
Uncertainty of user environment . Computer configuration for different users , The type of browser can bring uncertainty to the performance of the application . Although “ In case the user forbids JavaScript How to operate ?” This kind of worry seems a little bit groundless now , but JavaScript running speed , The uncertainty caused by differences in the user environment, such as the browser's support for scripts and even cache problems, is much greater than the code running on a controllable server .
2.
Privacy and security of code . use JavaScript Writing business logic code means that your system is exposed to the public . Remove security concerns , Just expose it to the public , It will make us accustomed to protecting the intellectual property rights of code for a long time , Try every means to hide , encryption , Software companies and programmers who mess up code feel uncomfortable , It's like losing privacy . More Than This , The data interface on the server side has also become visible to outsiders , Therefore, the security of their writing also needs to be improved .
3.
JavaScript. In fact, there are different opinions on this point .JavaScript And server language Java,C#,Python,PHP Is it more suitable to write complex code for business logic , You hate it. There's no compile time checking , Difficult to debug and test , Language design defects or like its simplicity , flexible , Functional programming ? This is probably for a programmer , Determinants of which development model to adopt .

Past client applications , Fat clients are called fat clients , In this contrast Web The browser used in the system is a thin client . Feng Shui turns , Now, with more and more code in a system JavaScript to write , Browsers are becoming rich clients . However, the motivation and logic behind it are the same , The user is God . The previous conversion is to save users time to install and update , The last conversion is to allow users to enjoy faster speed and rich functions . In the field of mobile phone development , The pattern goes back to the client ——App, Because it runs locally App Not only faster , It can be run offline , You can also call the camera , geographical position , Mobile phone hardware functions such as microphone and receiver , In short, it is to let users have a better experience , And the programmers behind it may gnaw at books to update their skills , Or the waves behind the Yangtze River push the waves ahead .

Technology
©2019-2020 Toolsou All rights reserved,
Hundreds of millions of locusts rarely collide Locusts want to be self driving Heroes Share has surpassed Ningde Era !LG Chemical confirmation to spin off battery business unit TypeScript Data types in is enough Python Garbage collection and memory leak msf Generate Trojan horse attack android mobile phone Element-UI Implementation of secondary packaging TreeSelect Tree drop-down selection component element-ui+vue-treeselect Verification of drop down box Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class A guess number of small games , use JavaScript realization Unity3D Input Key system