So far, we've learned how to intercept requests and either return or even enhance the response from our local system. Now, we will learn how to save requests when we are in offline mode and then send the calls to the server once we appear online.
Let's go ahead and set up a new folder for just this. Follow these steps:
- Create a folder called offline_storage and add the following files to it:
- index.html
- main.css
- interactions.js
- OfflineServiceWorker.js
- Add the following boilerplate code to index.html:
<!DOCTYPE html><html> <head><!-- add css file --></head> <body> <h1>Offline Storage</h1> <button id="makeRequest">Request</button> <table> <tbody id="body"></tbody> </table> <p>Are we online?: <span id="online">No</span> ...