Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

558 CHAPTER 15 Local data with web storage


Looking beyond plug-ins
Although the features within these plug-ins provided great answers to the storage problem,
they came with limitations that restricted their usefulness.
■■Plug-in required The first hurdle is that the user must not only have the plug-in
installed but also often have the correct plug-in version.
■■User blocking Because of security and performance concerns, many users install
tools such as Flash blockers, which can require a user to click to enable the plug-in or
even block the plug-in entirely.
■■Corporate users In some organizations, employees are prohibited from installing
third-party plug-ins to avoid potential security vulnerabilities.
■■Vendor-specific The biggest drawback to each plug-in option is that it relies on
individual vendors for support and development. If that vendor decides to discontinue
or reduce support, you might have to find another solution quickly.

Understanding HTML5 storage


Existing solutions leave a lot to be desired; HTML5 breaks new ground with several innova-
tive tools. Each is unique and carries its own set of pros and cons, which this chapter discusses
individually.
■■Web storage Easily the simplest new form of storage, web storage provides a way to
store key/value pairs of data in a manner that rivals cookies in ease of use. In the next
section, you see that it’s currently the most widely supported option.
■■Web SQL database For more complex applications, this might be a good alternative
to web storage. It provides the power of a full relational database, including support
for SQL commands, transactions, and performance tuning. Unfortunately, its support is
extremely limited, and it might be left behind in favor of other options.
■■IndexedDB This tool appears to be a strong candidate for the solution to complex
storage requirements in the future. As a non-relational (NoSQL) database, it provides
simplicity that’s similar to web storage while still accommodating common needs such
as indexing and transactions.
■■Filesystem API his tool is useful for storing larger data types such as text files, T
images, and movies. However, it suffers from a lack of adoption by many of today’s
modern browsers. As of this writing, it’s primarily supported in Chrome only.

Considering security
Although the four storage types have many differences, they also have some striking similari-
ties beyond all being vehicles for storing data on the client’s machine.
One property they all have in common is that the data being stored is tied to the URL
(or, more specifically, the origin), which ensures that data can’t be accessed by other sites.
Free download pdf