HTML5 storage types: 1. Local storage "localstorage", suitable for long-term storage of data; 2. Local storage "sessionstorage", the stored data is automatically deleted after the browser is closed; 3. Offline cache "application" cache", locally cache files required by the application.
The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.
Before h5, cookies were mainly used for storage. The disadvantage of cookies is that they carry data in the request header, and the size is within 4k. Main Domain pollution.
Main applications: shopping cart, customer login
For IE browser, there is UserData, the size is 64k, only IE browser supports it.
HTML5 provides two new methods of storing data on the client side:
- localStorage - data storage without time limit
- sessionStorage - data for a session Storage
1. Local storage localstorage
The data stored by the localStorage method has no time limit. The data is still available after the next day, week or year.
localStorage: suitable for long-term storage of data, the data will not be lost after the browser is closed;
Storage method:
With key-value pairs (Key- Value), it is stored permanently and will never expire unless manually deleted.
Size:
5M per domain name
Support:
Note: IE9 localStorage does not support local files. You need to deploy the project to the server to support it!
Detection method:
if(window.localStorage){ alert('This browser supports localStorage'); }else{ alert('This browser does NOT support localStorage'); }
Commonly used API:
getItem //Get record
setIten//Set record
removeItem//Remove record
key//Get The value corresponding to the key
clear//Clear the content stored in the record
##:
Array, picture, json, style, script. . . (As long as the content can be serialized into a string, it can be stored) 2. Local storage sessionstorageThe localStorage and sessionStorage in the local storage API of HTML5 are the same in usage. The difference is The reason is that sessionStorage is cleared after closing the page, while localStorage will always be saved. 3. Offline cache (application cache) HTML5 introduces the application cache, which can cache the web and use it when there is no network. Create an application by creating a cache manifest file. cache. Local cache files required for applicationUsage:
①Configure manifest fileOn the page:
<!DOCTYPE HTML> <html manifest="demo.appcache"> ... </html>
Manifest files:
Manifest files are simple text files that tell the browser what is cached (and what is not cached). Manifest files can be divided into three sections: ①CACHE MANIFEST - Files listed under this heading will be cached after the first download
②NETWORK - Files listed under this heading require a connection to the server and will not be cached
③FALLBACK - Files listed under this heading Specifies the fallback page when the page cannot be accessed (such as the 404 page)
Full demo:
CACHE MANIFEST # 2016-07-24 v1.0.0 /theme.css /main.js NETWORK: login.jsp FALLBACK: /html/ /offline.html
On the server: The manifest file needs to be configured The correct MIME-type, which is "text/cache-manifest".
<mime-mapping> <extension>manifest</extension> <mime-type>text/cache-manifest</mime-type> </mime-mapping>
Commonly used API:
The core is the applicationCache object, which has a status attribute indicating the current status of the application cache. : 0 (UNCACHED) : No cache, that is, there is no application cache related to the page 1 (IDLE) : Idle, that is, the application cache has not been updated 2 ( CHECKING): Checking, that is, the description file is being downloaded and checking for updates 3 (DOWNLOADING): Downloading, that is, the application cache is downloading the resources specified in the description file 4 (UPDATEREADY): The update is completed and all resources have been downloaded5 (IDLE): Abandoned, that is, the application cache description file no longer exists, so the page can no longer access the application cacheRelated Events:
Indicates changes in the application cache status: checking: Triggered when the browser looks for updates for the application cache error: When checking for updates or downloading Triggered when an error is sent during the resource noupdate: Triggered when checking the description file and finding that the file has no changes downloading: Triggered when starting to download application cache resources progress: In the file Triggered by continuous downloading during the process of downloading the application cacheupdateready: Triggered when the new application cache on the page has been downloadedcached: Triggered when the application cache is fully availableApplication Cache’s three advantages:
① Offline browsing② Improve page loading speed③ Reduce server pressureNotes:
1. Browsers may have different capacity limits for cached data (the limit set by some browsers is 5MB per site)
2 . If the manifest file or one of the files listed internally cannot be downloaded normally, the entire update process will be regarded as a failure, and the browser will continue to use the old cache
3. The HTML that references the manifest must have the same origin as the manifest file and be in the same location. Under a domain
4. The browser will automatically cache the HTML file that references the manifest file. This means that if the HTML content is changed, the version needs to be updated to be updated.
5. The CACHE in the manifest file has nothing to do with the position order of NETWORK and FALLBACK. If it is an implicit declaration, it needs to be at the front.
6. The resources in FALLBACK must have the same origin as the manifest file
7. Update After completing the version, you must refresh it once before starting the new version (the page will be refreshed once), and you need to add a listening version event.
8. Even if the manifest attribute is not set for other pages in the site, the requested resource will be accessed from the cache if it is in the cache
9. When the manifest file changes, the resource request itself will trigger an update
The difference between offline caching and traditional browser caching:
1. Offline caching is for the entire application, and the browser cache is a single file
2. Offline caching is broken You can still open the page even if you are online, but the browser caching is not working
3. Offline caching can actively notify the browser to update resources
Related recommendations: "html video tutorial"
The above is the detailed content of What types of storage methods are there in html5?. For more information, please follow other related articles on the PHP Chinese website!

useState allows state to be added in function components because it removes obstacles between class components and function components, making the latter equally powerful. The steps to using useState include: 1) importing the useState hook, 2) initializing the state, 3) using the state and updating the function.

React's view focus manages complex application state by introducing additional tools and patterns. 1) React itself does not handle state management, and focuses on mapping states to views. 2) Complex applications need to use Redux, MobX, or ContextAPI to decouple states, making management more structured and predictable.

IntegratingReactwithotherlibrariesandframeworkscanenhanceapplicationcapabilitiesbyleveragingdifferenttools'strengths.BenefitsincludestreamlinedstatemanagementwithReduxandrobustbackendintegrationwithDjango,butchallengesinvolveincreasedcomplexity,perfo

TomakeReactapplicationsmoreaccessible,followthesesteps:1)UsesemanticHTMLelementsinJSXforbetternavigationandSEO.2)Implementfocusmanagementforkeyboardusers,especiallyinmodals.3)UtilizeReacthookslikeuseEffecttomanagedynamiccontentchangesandARIAliveregio

SEO for React applications can be solved by the following methods: 1. Implement server-side rendering (SSR), such as using Next.js; 2. Use dynamic rendering, such as pre-rendering pages through Prerender.io or Puppeteer; 3. Optimize application performance and use Lighthouse for performance auditing.

React'sstrongcommunityandecosystemoffernumerousbenefits:1)ImmediateaccesstosolutionsthroughplatformslikeStackOverflowandGitHub;2)Awealthoflibrariesandtools,suchasUIcomponentlibrarieslikeChakraUI,thatenhancedevelopmentefficiency;3)Diversestatemanageme

ReactNativeischosenformobiledevelopmentbecauseitallowsdeveloperstowritecodeonceanddeployitonmultipleplatforms,reducingdevelopmenttimeandcosts.Itoffersnear-nativeperformance,athrivingcommunity,andleveragesexistingwebdevelopmentskills.KeytomasteringRea

Correct update of useState() state in React requires understanding the details of state management. 1) Use functional updates to handle asynchronous updates. 2) Create a new state object or array to avoid directly modifying the state. 3) Use a single state object to manage complex forms. 4) Use anti-shake technology to optimize performance. These methods can help developers avoid common problems and write more robust React applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools
