Different Storage Options In HTML5

Posted By : Pawanpreet Singh | 28-Dec-2017

Objective:-

  • Learn various types of storage options in client side.
  • Which one to use at a certain occasion.

Types:-

  1. Web Storage - localStorage and sessionStorage
  2. Web SQL
  3. IndexedDB

WebStorageWeb apps using web storage can save data in the local memory of person browser.

Before this data was stored in cookies. Web storage can store a large amount of application data and it's more secure than cookies. Web Storge save data based on origin, all web pages can access same data if their origin is same as (origin = www.xyz.com).

 

localStorage - store data in browsers memory without any expiry.

sessionStorage - store data in browsers memory for a particular session.

 

                 // Save
localStorage.setItem("name", "Pawanpreet");
// Get
document.getElementById("output").innerHTML = localStorage.getItem("name");

        

 

Web SQL - It is a web API for saving data in DB which can be accessed using SQL. Because one can access use it using SQL statements it is known as WebSql.

Main methods of webSql are as below

  • openDatabase - this function will use an existing database or create the new one if not found.
  • transaction - this function provides the power to control the transaction either complete it or roll back the transaction.
  • executeSql - this function is used to run SQL queries.

IndexedDB - IndexedDB unlike WebSql does not save data in fixed columns but save data in the js based object-oriented database object. Using this one can save and access data using “key”. Like WebSql indexDB also work on the same origin.

Features:

  • Store data in a Key-Value form.

  • Based on Transactional DB model.

  • Most of API’s are asynchronous.

  • Uses event based on DOM to notify availability of result.

  • It is Object Oriented.

  • Does not use SQL statements.

  • Use same origin Policy.

 

About Author

Author Image
Pawanpreet Singh

Pawanpreet is an seasoned Project Manager with a wealth of knowledge in software development, specializing in frontend and mobile applications. He possesses a strong command of project management tools, including Jira, Trello, and others. With a proven track record, he has successfully overseen the delivery of multiple software development projects, managing budgets and large teams. Notable projects he has contributed to include TimeForge, Yogyata, Kairos, Veto, Inspirien App, and more. Pawanpreet excels in developing and maintaining project plans, schedules, and budgets, ensuring timely delivery while staying within allocated resources. He collaborates closely with clients to define project scope and requirements, establish timelines and milestones, and effectively manage expectations. Regular project status meetings are conducted by him, providing clients and stakeholders with consistent updates on project progress, risks, and issues. Additionally, he coaches and mentors project leads, offering guidance on project management best practices and supporting their professional development.

Request for Proposal

Name is required

Comment is required

Sending message..