当前位置:网站首页>Spa single page application
Spa single page application
2022-07-03 07:18:00 【darabiuz】
1. Definition of single page application
1. What is a single page
A single page does not mean that a web page has only one page , It means that this web page can have 1 To multiple different pages , But its entry file only index.html This one , Other pages are through js Control route jump to realize page Jump
2. Contrast with traditional multi page mode

- As can be seen from the figure above , Traditional multi page mode application , Every time the interface is refreshed, it will be re requested by the server html file , Early Web Application , The role of the front end is weak , Business logic and data processing are on the back end , The back end returns a HTML page , The front end is only responsible for displaying . In this mode , Single HTML The page is treated as a functional original , Form submission , Hyperlink jump can be used to re request new HTML page , So as to show users a new page . In this way , You can feel that the page is always refreshing , A click may take a long time , This is because , When the page changes , All resources need to be re requested . These problems lead to poor user experience , And wasted resources .
- If you use single page mode , First completion html After file request , Later, send the request like the background again , The background returns only updated data data , It can dynamically rewrite the current page to interact with users , Instead of reloading the entire page . The fluency of single page applications makes Web Applications are more like desktop or Native Applied . Compared with the traditional Web application , Single page application achieves the separation of front and back ends , The back end is only responsible for processing data and providing interfaces , Page logic and page rendering are left to the front end . The front end is now , Single page applications have been widely used , Current React、Vue、Angular And so on SPA principle . Single page application means that the front end has the initiative , It also makes the front-end code more complex and huge , modularization 、 Componentization and architecture design are becoming more and more important
2. How to realize single page
1. location.hash
We can monitor # The change after the sign (hashChange), To dynamically change the content of the page .URL Of # The address after the number is called hash, This is what we call Hash Pattern , It's a very typical front-end routing method .
2. window.history
This way is used History API,History API As the name suggests, it's for historical records API , The principle of this mode is to save the state of the page to an object first (state) in , When the page of URL When changing, find the corresponding object , To restore this page . In fact, this function was originally designed to facilitate the browser to move forward and backward , Using this pattern , You can get rid of # Implement front-end routing with .
Vue Two modes of front-end routing have been provided for us , We don't have to do it ourselves .
3. SPA Advantages and disadvantages
The advantages are :
No refresh experience , Users will not be frequently “ interrupt ”, Because the interface framework is local , The response to users is very timely , Therefore, the user experience is improved ;
Separate front and rear concerns , The front end is responsible for interface display , The back end is responsible for data storage and computing , Attend to each one's own duties , Don't mix the front and back logic ;
Reduce server pressure , The server can only use data , Regardless of presentation logic and page composition , Throughput will increase several times ;
API share , The same set of back-end program code , Can be used without modification Web Interface 、 mobile phone 、 Tablet and other clients ;
Full front-end componentization , Front end development is no longer page based , Use more of the idea of componentization , Code structure and organization are more standardized , Easy to modify and adjust .
Disadvantages are :
Yes SEO Not very good , Multi page application is right SEO Amicable , Because what is returned to the front end is the rendered HTML structure , The content inside can be captured by crawlers , Though it can be done by Prerender Pre rendering optimization and other technologies solve part of , But it is relatively difficult to index it ;
Error prone , Need to use program management to move forward 、 back off 、 Address bar and other information ;
High front-end development threshold , High demand for technical ability , You need to have a certain understanding of design patterns , Because facing is not a simple page , It's a desktop software running in a browser environment .
边栏推荐
- I. D3.js hello world
- Discussion on some problems of array
- [Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
- 691. 立方体IV
- 3311. Longest arithmetic
- 1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- Pits encountered in the use of El checkbox group
- PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef
- Thoughts in Starbucks
- Operation and maintenance technical support personnel have hardware maintenance experience in Hong Kong
猜你喜欢

多个全局异常处理类,怎么规定执行顺序

Pat grade a real problem 1166

Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
![[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*](/img/1f/f579110a408c5b5a094733be57ed90.jpg)
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*

docker建立mysql:5.7版本指定路径挂载不上。
![[HCAI] learning summary OSI model](/img/90/66505b22e32aa00b26886a9d5c5e4c.jpg)
[HCAI] learning summary OSI model

My 2020 summary "don't love the past, indulge in moving forward"

3311. Longest arithmetic

Selenium key knowledge explanation
![[solved] unknown error 1146](/img/f1/b8dd3ca8359ac9eb19e1911bd3790a.png)
[solved] unknown error 1146
随机推荐
691. Cube IV
Arctic code vault contributor
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
树莓派更新工具链
Specified interval inversion in the linked list
Notes on the core knowledge of Domain Driven Design DDD
高并发内存池
PHP install composer
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
[set theory] partition (partition | partition example | partition and equivalence relationship)
Pat grade a real problem 1166
Distributed transactions
II. D3.js draw a simple figure -- circle
Resthighlevelclient gets the mapping of an index
PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef
【CMake】CMake链接SQLite库
4279. Cartesian tree
dataworks自定义函数开发环境搭建
Advanced API (multithreading)
Troubleshooting of high CPU load but low CPU usage