Skip to Content
Building Progressive Web Apps
book

Building Progressive Web Apps

by Tal Ater
September 2017
Intermediate to advanced
285 pages
7h 11m
English
O'Reilly Media, Inc.
Content preview from Building Progressive Web Apps

Chapter 6. Storing Data Locally with IndexedDB

So far we used CacheStorage to store all of the files as well as the data our app needs. When we wanted to store a list of reservations, we simply cached an HTTP response containing a JSON file with that data in CacheStorage. We were then able to fetch that file from cache and parse it every time we wanted to access the list of reservations. But what happens when the user makes a new reservation or a reservation’s status changes? At this point, we had to resort to loading a new, up-to-date JSON file from the server.

While our app was fully operational regardless of the user’s connection, can it truly be called offline-first when it relies so heavily on the server for even the simplest data manipulation?

We need a better way to handle data persistently in the browser. One that allows us to store, read, and modify data locally, without relying on the network.

In this chapter, we will add this important tool to our toolset and learn how to use a local database called IndexedDB.

Just like server-side databases, IndexedDB allows us to store data in a structured way, query it, modify it, and more. Unlike server-side databases, IndexedDB can do all of this entirely in the browser.

The chapter begins with a general introduction to IndexedDB and its syntax, and the code we will experiment with here will be unrelated to the Gotham Imperial Hotel. Later, we will take the lessons we have learned and implement them in the Gotham Imperial Hotel ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Progressive Web Apps

Progressive Web Apps

Dean Hume

Publisher Resources

ISBN: 9781491961643Errata Page