当前位置:网站首页>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 .
边栏推荐
- New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
- Hash table, generic
- Arduino Serial系列函数 有关print read 的总结
- Split small interface
- JMeter JSON extractor extracts two parameters at the same time
- 【已解决】win10找不到本地组策略编辑器解决方法
- Basic components and intermediate components
- My 2020 summary "don't love the past, indulge in moving forward"
- The education of a value investor
- Common analysis with criteria method
猜你喜欢
带你全流程,全方位的了解属于测试的软件事故
3311. Longest arithmetic
C代码生产YUV420 planar格式文件
7.2 brush two questions
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
SecureCRT取消Session记录的密码
Pat grade a real problem 1166
4279. 笛卡尔树
Common problems in io streams
Interview questions about producers and consumers (important)
随机推荐
MySQL transaction rollback, error points record
How to plan well?
SharePoint modification usage analysis report is more than 30 days
Selenium key knowledge explanation
Warehouse database fields_ Summary of SQL problems in kingbase8 migration of Jincang database
SecureCRT取消Session记录的密码
dataworks自定義函數開發環境搭建
sharepoint 2007 versions
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
[untitled]
树莓派更新工具链
[set theory] partition (partition | partition example | partition and equivalence relationship)
Interview questions about producers and consumers (important)
My 2020 summary "don't love the past, indulge in moving forward"
Setting up the development environment of dataworks custom function
Resthighlevelclient gets the mapping of an index
Sorting, dichotomy
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
Book recommendation~
7.2刷题两个