HTML and CSS Reference
In-Depth Information
chapter twelve
Storing Data
ALMOST ALL APPLICATIONS involve storing data of some kind. This can be data about users, products, videos,
or even page visits. Used correctly, this data can be a powerful tool in the decision-making process. That's why com-
panies like Google and Facebook try to collect as much data as they can about their users and their behaviors.
Web applications that handle a lot of data have traditionally used databases for storage. These databases are
stored on servers that are often hundreds, if not thousands, of miles away from the user (hence the term server-side
storage). An alternative option is client-side storage. Storing data on the client side means that it is stored on the user's
computer or device—the client —as opposed to being stored on a web server. In this chapter, you learn about the
strengths and weaknesses of using client-side storage. You explore two new technologies that HTML5 introduces for
storing data on the client side and learn how these technologies can be used in modern web applications and websites
to boost performance and make websites function offline.
More pros and cons of using client-side storage are discussed in the last portion of this chapter.
Why Use Client-Side Storage?
There are many reasons why you might want to store data on the client. In this section, I explore some of the most im-
portant, such as the following:
Performance —With a traditional website, every time an application wants to fetch some data, it has to send a
request to the server, wait for it to respond, and then download the response. This all takes time and can slow
down the user's browsing experience. If you store data on the client, it can be accessed much more quickly
because there is no need to make lengthy HTTP requests. Just to clarify: By lengthy, I mean 200 to 400 milli-
seconds (more on mobile devices). This might not sound like a lot, but it all adds up.
Offline access —The capability to access your data offline is another reason why many developers prefer to
keep data on the client side. This is especially prudent for web applications built for mobile phones; these
devices are more likely to be without a stable Internet connection at some point in the day. If the data is
stored on the device, it can be accessed without having to talk to a web server.
No cookies —Before HTML5 came along, most client-side data was stored using cookies, small pieces of data
stored in the browser. Cookies have several problems that make them unsuitable for storing a relatively large
quantity of data. The first problem is that cookies are limited in size—to be specific, 4096 bytes. That's not
much space for storing data. The other big drawback is that cookies are sent with every request your browser
makes to the web server, whether needed or not. This increases the amount of time each request takes to com-
plete, and therefore affects your application's performance.
Search WWH ::




Custom Search