Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

Lesson 1: Introducing web storage CHAPTER 15 557


$.cookie('firstName', 'Glenn');
var firstName = $.cookie('firstName');

This example shows that the plug-in provides a much simpler interface.

Working with cookie limitations


Cookies will continue to be an effective tool for the foreseeable future, but they have some
drawbacks.
■■Capacity limitations Cookies are limited to about 4 KB of data, which is not large,
although you can create more than 30 cookies per site. (The actual maximum limit
depends on which browsers you are targeting; the average is between 30 and 50.)
■■Overhead Every cookie is sent with each HTTP request/response made, regardless of
whether the values are needed. This is often true even for requests for static content
(such images, css files, and js files), which can create heavier-than-necessary HTTP
messages.

Alternatives to cookies prior to HTML5


Because the limitations of cookies were so high, demand was great for more powerful stor-
age capabilities. Some creative alternatives were developed within a few of the more popular
plug-ins.
■■Flash Player Adobe Flash Player plug-in was one of the earliest to offer a reliable
storage mechanism through its Local Shared Objects function. It comes with the abil-
ity to store much more data than cookies and gives the user the ability to increase or
limit the amount of space allowed for each site. Another extremely useful feature of
Local Shared Objects is its ability to be written by one browser and read by others. For
example, if a user creates a to-do list on a website by using Internet Explorer, that list
can later be accessed by Flash Player running within Firefox.
■■User Data Internet Explorer has supported an application programming interface
(API), referred to as User Data, since version 5. It provides the ability to store up to
1 MB of information in the form of a key/value pair. Although not as robust as the
HTML5 storage offerings, it can still be a good alternative for applications that are
meant to be Internet Explorer–specific and are required to work in earlier versions such
as Internet Explorer 6 or Internet Explorer 7.
■■Google Gears A solution that was ahead of its time was Google Gears, which several
high-volume web utilities used, such as YouTube and Gmail. In 2010, however, Google
announced that it is no longer developing new features for Gears. Instead, Google’s
efforts are turned to building on the HTML5 web standards.
■■Java Applets Another popular open-source solution was Java Applets, which was
another cross browser–friendly way to store information. However, like Flash Player
and Gears, its usage is dropping dramatically in favor of HTML5 alternatives.
Free download pdf