`
leonzhx
  • 浏览: 796886 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

A Place To Put Your Stuff

 
阅读更多

1.   Cookies have three potentially dealbreaking downsides:

 

  a)  C ookies are included with every HTTP request, thereby slowing down your web application by needlessly transmitting the same data over and over

  b)   Cookies are included with every HTTP request, thereby sending data unencrypted over the internet (unless your entire web application is served over SSL)

  c)   Cookies are limited to about 4 KB of data — enough to slow down your application (see above), but not enough to be terribly useful

 

2.   Microsoft invented DHTML Behaviors , and one of these behaviors was called userData . userData allows web pages to store up to 64 KB of data per domain, in a hierarchical XML-based structure. IE does not present any form of permissions dialog, and there is no allowance for increasing the amount of storage available.

 

3.   In 2002, Adobe introduced “Flash cookies” in Flash 6. The feature is properly known as Local Shared Objects . Briefly, it allows Flash objects to store up to 100 KB of data per domain. By 2006, with the advent of ExternalInterface in Flash 8, accessing LSO s from JavaScript became an order of magnitude easier and faster. Brad rewrote AMASS and integrated it into the popular Dojo Toolkit under the moniker dojox.storage .

 

4.   In 2007, Google launched Gears , an open source browser plugin aimed at providing additional capabilities in browsers. Gears provides an API to an embedded SQL database based on SQLite . After obtaining permission from the user once, Gears can store unlimited amounts of data per domain in SQL database tables. This early prototype later influenced the creation of the Web SQL Database specification. By 2009, dojox.storage could auto-detect (and provide a unified interface on top of) Adobe Flash, Gears, Adobe AIR, and an early prototype of HTML5 storage that was only implemented in older versions of Firefox.

 

5.   HTML5 Storage is a way for web pages to store named key/value pairs locally, within the client web browser. Like cookies, this data persists even after you navigate away from the web site, close your browser tab, exit your browser, or what have you. Unlike cookies, this data is never transmitted to the remote web server (unless you go out of your way to send it manually). Unlike all previous attempts at providing persistent local storage, it is implemented natively in web browsers, so it is available even when third-party browser plugins are not.

 

6.   You’ll access HTML5 Storage through the localStorage object on the global window object.

 

7.   HTML5 Storage is based on named key/value pairs. The named key is a string. The data can be any type supported by JavaScript, including strings, Booleans, integers, or floats. However, the data is actually stored as a string. If you are storing and retrieving anything other than strings, you will need to use functions like parseInt() or parseFloat() to coerce your retrieved data into the expected JavaScript datatype.

interface Storage {

  getter any getItem(in DOMString key);

  setter creator void setItem(in DOMString key, in any data);

};
 

Calling setItem() with a named key that already exists will silently overwrite the previous value. Calling getItem() with a non-existent key will return null rather than throw an exception.

 

 

8.   You can treat the localStorage object as an associative array:

var foo = localStorage["bar"];

// ...

localStorage["bar"] = foo; 
 

 

9.   There are also methods for removing the value for a given named key, and clearing the entire storage area (that is, deleting all the keys and values at once).

interface Storage {

  deleter void removeItem(in DOMString key);

  void clear();

}; 
 

 

10.   There is a property to get the total number of values in the storage area, and to iterate through all of the keys by index (to get the name of each key).

If you call key() with an index that is not between 0–(length-1), the function will return null .

interface Storage {

  readonly attribute unsigned long length;

  getter DOMString key(in unsigned long index);

};
 

 

 

11.   The storage event is fired on the window object whenever setItem() , removeItem() , or clear() is called and actually changes something. If you set an item to its existing value or call clear() when there are no named keys, the storage event will not fire, because nothing actually changed in the storage area:

if (window.addEventListener) {

  window.addEventListener("storage", handle_storage, false);

} else {

  window.attachEvent("onstorage", handle_storage);

};
 

The handle_storage callback function will be called with a StorageEvent object, except in Internet Explorer where the event object is stored in window.event .

 

 

function handle_storage(e) {

  if (!e) { e = window.event; }

} 

 

 

12.   A StorageEvent object, which has the following useful properties:


 The storage event is not cancelable. It’s simply a way for the browser to tell you, “hey, this just happened. There’s nothing you can do about it now; I just wanted to let you know.”

 

13.   By default, the storage space is 5 megabytes across browsers, although it is phrased as no more than a suggestion in the HTML5 Storage specification. One thing to keep in mind is that you’re storing strings, not data in its original format. If you exceed your storage quota of 5 megabytes, you will get a “QUOTA_EXCEEDED_ERR ” exception. No browser supports any mechanism for web developers to request more storage space, although it can be a user-initiated action to control the storage space for some browsers.

 

14.   Another competing vision for advanced, persistent, local storage for web applications: the Indexed Database API , formerly known as “WebSimpleDB,” now affectionately known as “IndexedDB.” An early walk-through of IndexedDB is a good tutorial of how IndexedDB works, giving side-by-side comparisons of IndexedDB and Web SQL Database.

  • 大小: 30.5 KB
分享到:
评论

相关推荐

    [Head.First.JavaScript].Michael.Morrison...

    having a place to store all their stuff. Not so in JavaScript. You simply don’t have the luxury of walk-in closets and three-car garages. In JavaScript, everything has its place, and it’s your job ...

    VB编程资源大全(英文源码 表单)

    winhole.zip This example demonstrates how to put a hole in the center of a form.<END><br>15 , tileform.zip This will tile a picture on the background of your form.<END><br>16 , radiomnu.zip ...

    BURNINTEST--硬件检测工具

    - Note: We have seen a report of the Video Playback failing (crash) due to a faulty video codec, ffdshow.ax. If you are using this we suggest you try a different Video file and codec. Release ...

    VB编程资源大全(英文源码 数据库)

    querys and fields of a database and put them in a TreeView(using OpenSchema ADOConnection method)<END><br>7 , imagechunk1.zip This application will save JPG,BMP,GIF files in your database and ...

    Sakemail

    Some stupid mail servers put tabs in some fields (CC:, TO:) when they want to make a new line, the correct is to put at least a space in the beginning of the line, added a little code to "...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    When you include a header file you introduce a dependency that will cause your code to be recompiled whenever the header file changes. If your header file includes other header files, any change to ...

    VB编程资源大全(英文源码 网络)

    Source code + tutorial.<END><br>26 , chat.zip This code shows you how to creat a local network chat room so that you and your friends can have a chat room which nowone else can enter<END><br>27 , ...

    一本android的好书beginning android 2 和 源码

    Stuff at Your Disposal ■Chapter 2: Projects and Targets Pieces and Parts Creating a Project Project Structure Root Contents The Sweat Off Your Brow And Now, the Rest of the Story What You Get Out...

    Professional.MFC.with.VC6

    Adding a New Item to your Window Menu Two Views Automatically Changing Views in an SDI Application How MFC Reacts to Multiple Templates What Frames are For Status Bars and Toolbars CStatusBar ...

    ak2新版内核AKAIO1.5

    + DMA mode on AK2 (Hold A while loading a game to use non-DMA mode: Red text = DMA / Blue text = non-DMA). + New Super Mario Brothers Minigames on AK2: If they don't work, set Download Play to ...

Global site tag (gtag.js) - Google Analytics