Adding service workers to an Ember application is easy thanks to addons. To get started have an Ember app ready to go. For this tutorial, I followed the quickstart guides to get an Ember app up and running.
Checkout the quick start guides to get an app up and running (https://guides.emberjs.com/release/getting-started/quick-start/).
First, we need to serve up our application:
$ ember serve
and then go to http://localhost:4200/ in the browser
You'll know everything is working fine if you see the friendly tomster welcome page:
Now let's implement service worker support for offline caching by using the ember-service-worker addons:
is the base addon that registers a service worker with the browser.
caches the Ember app’s index.htmlfile.
caches an Ember app’s asset files. By default, it will cache anything in the /assets/ folder, but can be configured to cache additional assets.
resorts to a cached fallback version of a network response when a network request fails.
$ ember install ember-service-worker $ ember install ember-service-worker-index $ ember install ember-service-worker-asset-cache $ ember install ember-service-worker-cache-fallback
These plugins will take care of caching the index.html page and any static assets. Now if you turn off your internet and try to refresh the page the app will still load!