当前位置:网站首页>32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)
32: Chapter 3: development of pass service: 15: Browser storage media, introduction; (cookie,Session Storage,Local Storage)
2022-07-05 10:45:00 【Small withered forest】
explain :
(1) A brief introduction to browser storage media :cookie,Session Storage,Local Storage;
(2) So far 、 Certain points :
● These storage media are browser , We need browser permission to use these storage media ;
● When the back end responds to the front end , Set up cookie;; When you get the front end , You can set it in the browser ;
● then , How do you feel at the moment “Session Storage,Local Storage Set up ”, More work needs to be done by the front end ;( such as ,【 Save the data to Session Storage,Local Storage in 】、【 When the front end makes a second request , No more requests for back-end interfaces , But to go “Session Storage,Local Storage” To take 】、【 In some cases , You need to remove Session Storage,Local Storage The content in 】 wait ;;; These jobs , I feel that more needs to be written in the front-end code )
(3) This blog , Just an introduction to browser storage media , It's just some fur ; You can refer to 【localStorage、sessionStorage and Cookie Difference and usage 】、【localStorage and sessionStorage The local store 】 etc. ;
Catalog
zero : Rationality of this blog ;
zero : Rationality of this blog ;
(1) Explain the problem ;
● We are 【31: The third chapter : Developing a pass service :14: Development 【 Get basic user information , Interface 】;】, This interface is used by users to obtain basic user information ;
● And in this project , Almost every page is loaded , Many will go to get user information ;
● It also means that , If so ;;; that , We are loading almost every page , The front end will silently call 【 Get basic user information , Interface 】, In order to get the basic information of users ;
● that , In this way ,【 Get basic user information , Interface 】 The pressure will be great ;( because , As long as we enter this website , Refresh the page , When clicking on the page , Every page will silently call this interface ,,, This traffic is very large )
● Even if 【 Get basic user information , Interface 】 No operation database , The traffic of requesting this interface is also a great burden ;
……………………………………………………
【 Get basic user information , Interface 】 There are two main characteristics : The first is the information provided by this interface , Generally, it is not often modified ; Two is , Many places need the information provided by this interface , That is, the request flow of this interface is very large ;
(2) Solutions ;
● 【 Get basic user information , Interface 】 This interface queries “ Basic information of users ”;;; and “ Basic information of users ”, Not all users often modify it frequently ;
● therefore , We can “ Basic information of users ”, Store on Browser ; thus , It can reduce the pressure of the interface ;
● In our project , After our front-end obtains the basic user information , Save the basic user information in the browser Session Storage in ;
● such as , We are visiting the project , And change / After improving user information , You can see Session Storage;
● thus , In the first need “ Basic information of users ” When , It will actually call the backend 【 Get basic user information , Interface 】;;; however , As long as the user doesn't close the browser , The current page needs “ Basic information of users ” When , It will no longer call the backend 【 Get basic user information , Interface 】 了 , But directly from Session Storage I got ;;;;; And this ,【 Get basic user information , Interface 】 The pressure will be reduced , Save a lot of traffic ;
One : Browser storage media , brief introduction ;
1.cookie;
(1)cookie It can be regarded as a kind of cache ;
(2) In the early days , There are many in the website ; For example, in this project uid and utoken It's stored in cookie Medium ; adopt cookie Data stored in , The front-end and back-end can interact with some data ;
(3)cookie It's saved in the browser :
● If the expiration time is not set , that cookie Is stored in the content ; If we close the browser , So with this cookie It's gone ;( It's kind of like session The effect of conversation )
● If the expiration time is set , that cookie It is stored in the hard disk ; After closing the browser , This still exists ; commonly , In many websites ,cookie The expiration time of is set to 7 God ;
(4)cookie Only string contents can be saved ;;; Image object 、List these , We need to turn it into JSON Character creation , Then save ;
(5)cookie Can only save 【 size <4k Left and right strings 】;;; If a string is too large , You can't save it cookie It's in ;
(6) When a user visits a website while using a browser , You can disable the browser cookie;;; In this way , Even if the website system is in the code , Yes “ Store cookie” Code for , It can't be saved ;
stay HTML5 in the future , Then the browser can use webStorage( Include sessionStorage、localStorage), In fact, it is also a similar form of data storage , It's right cookie It's an improvement on .
2.webStorage;
Session Storage;
It can be understood in this way :
● The user opens the browser , To visit A Website , Until the user completely turns off the browser : In this time , We call it a conversation (session);
● In the process , The browser will target A There is a Session Storage;
● If A There is a direction in the code of the website Session Storage The action of storing data , Then the data will be saved to Session Storage In the middle ;
● As long as we don't close the browser , These exist Session Storage The data in will always be ;;; however , Once we close the browser , This conversation (session) And that's it , Then those exist Session Storage The data in is gone ;
……………………………………………………
Local Storage;
(1)Local Storage The data is saved locally ( disk ) Of ;; We close the browser 、 After restarting the computer , These data will be in ;( This is actually a manifestation of data persistence )
(2)Session Storage and Local Storage Able to survive 【 Size in 5M Left and right data 】, This is more than cookie Much larger ;
(3) and , In terms of security ,Session Storage and Local Storage than cookie Better ;;;cookie Will be asked to carry , There may be some cookie Tampering 、cookie Hijacking and other security issues ;
(4) adopt webStroage, After caching most website data , It can load faster , It can also reduce some pressure for concurrency .
边栏推荐
- 32:第三章:开发通行证服务:15:浏览器存储介质,简介;(cookie,Session Storage,Local Storage)
- 2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
- Learning note 4 -- Key Technologies of high-precision map (Part 2)
- Workmanager learning 1
- BOM//
- Based on shengteng AI Yisa technology, it launched a full target structured solution for video images, reaching the industry-leading level
- "Everyday Mathematics" serial 58: February 27
- Ad20 make logo
- Go项目实战—参数绑定,类型转换
- 正则表达式
猜你喜欢
Go语言-1-开发环境配置
非技术部门,如何参与 DevOps?
DGL中的消息传递相关内容的讲解
"Everyday Mathematics" serial 58: February 27
Learning II of workmanager
Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
微信核酸检测预约小程序系统毕业设计毕设(6)开题答辩PPT
How does redis implement multiple zones?
微信核酸检测预约小程序系统毕业设计毕设(7)中期检查报告
Secteur non technique, comment participer à devops?
随机推荐
Talk about the understanding of fault tolerance mechanism and state consistency in Flink framework
SAP UI5 ObjectPageLayout 控件使用方法分享
Review the whole process of the 5th Polkadot Hackathon entrepreneurship competition, and uncover the secrets of the winning projects!
Node の MongoDB Driver
中职组网络安全C模块全漏洞脚本讲解包含4个漏洞的脚本
QT implements JSON parsing
Completion report of communication software development and Application
dsPIC33EP 时钟初始化程序
Write double click event
NAS and San
What are the top ten securities companies? Is it safe to open an account online?
想请教一下,十大券商有哪些?在线开户是安全么?
Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
运算符、、
GBase 8c数据库如何查看登录用户的登录信息,如上一次登录认证通过的日期、时间和IP等信息?
微信核酸检测预约小程序系统毕业设计毕设(6)开题答辩PPT
重磅:国产IDE发布,由阿里研发,完全开源!
C语言活期储蓄账户管理系统
【SWT组件】内容滚动组件 ScrolledComposite