Local Storage and offline applications

Source: Internet
Author: User
Tags sessionstorage


Data is stored locally on the Web Client. Improve the cookies storage mechanism in html4.
: Used to save the data you want to save from entering the website to closing the browser.
SessionStorage. setItem (key, value), sessionStorage. getItem (key );
: Save the data to the local hardware device of the client. You can continue to use the data in the browser next time.
LocalStorage. setItem (key, value), localStorage. getItem (key). clear () method.

Create a database access object:
Var db = openDatabase ('mydb', '1. 0', 'test db', 2*1024*1024); // Database Name, version number, description, size
Transaction: transaction uses the callback function.
Db. transaction (function (tx ){
Tx.exe cuteSql ('create table if not exists LOGS (id unique, log text )');
});
Execute the query using executeSql:
Transaction.exe cuteSql (sqlquery, [], dataHandler, errorHandler );//
Parameter: 1-SQL statement (the parameter uses "? "Replace, and put these parameters in the second one in sequence ),
2-parameter array,
3-callback function after success: function dataHandler (transaction, result ){...}
4-callback function when an error occurs: function errorHandler (transaction, errmsg ){...}
The result DataSet object result has a rows attribute, such as rows. length, rows [index], and rows. Item ([indexx.


Local cache.
Differences between local cache and browser Web Cache:
File:
The local cache is managed by the manifest file on each page.
This file lists the resource files that need to be cached or do not need to be cached, and the resource file access path.
You can specify a manifest file for each page or a total manifest file for the entire web application.

You need to configure the server to support the text/cache-manifest MIME type.
Add "manifest" type "text/cache-manifest" to the MIME ing in IIS"
Specify manifest for the page: The interaction process between the browser and the server:
When accessing the website for the first time, after obtaining all the resources on a page, process the manifest file, request the resources to be cached again, update the cache, and trigger an event to notify the local cache to be updated.
The next time you visit the website, use the local resources and then request manifest.
ApplicationCache:
When the browser updates the local cache and loads the new resource file, the updateready event of the applicationCache object is triggered, notifying that the local cache has been updated. In this event, you can manually refresh the page to obtain the latest version of the application.
SwapCache method: Used to manually update the local cache. It can only be called when an updateready event is triggered.
Event: a series of events are triggered when the browser interacts with the server.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.