Utilizing web storage

Any web application developer who has worked on any application that involves even a little user management will for sure have heard about web cookies, which in essence provide a mechanism for storing some of the information on the client side.

Utilizing cookies provides an easy way through which we can maintain small amounts of user data on the client side and can read it multiple times until the cookies expire. But as easy as it is to deal with cookies, there are certain limitations that restrict the cookies being used for anything useful, other than maintaining a small amount of application state on the client side. Some of these limitations are as follows:

  • Cookies are transferred with every request, hence adding to the data that is transferred with every request
  • Cookies allow for storing a little amount of data that is restricted to a maximum of 4 KB

Now, the question that comes is, what can we do if we want to store more data or we want to avoid fetching the same set of stored data again and again with every request?

For dealing with such scenarios, the latest version of HTML, HTML 5, provides various functionalities that allow for dealing with client-side web storage. This web storage provides a number of benefits over the cookies-based mechanism, such as the following:

  • Since the web storage is available directly on the client side, the information doesn't need to be sent by the server again and again to the client with every request
  • The web storage API provides a maximum of 10 MB of storage, which is multiple times grater than what can be stored with the cookies
  • Web storage provides the flexibility of storing the data either in local storage, for example, the data will be accessible even after the user closes and opens a browser again, or on a per session basis, where the data stored in the web storage will be cleared off as soon as the session is invalidated, either when the user session is destroyed by your application handler responsible for handling the user log out, or the browser is closed

This makes web storage an attractive place to put in the data and avoid loading it again and again.

For our enterprise applications, this can provide a lot of flexibility by storing the results of the intermediate steps in the user browser only, and then submitting them back to the server only when all the required input fields have been filled up.

One other use case that may be more specific to Bugzot is that, we can store the bug report that a user is filing into the web storage and send it to the server when the bug report is completed. In this case, the user gets the flexibility to come back to working on their bug reports as and when they wish, without worrying about starting from scratch again.

Now that we know about the benefits that web storage provides, let's take a look at how we can leverage the use of web storage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.5