Besides plugin configuration, you also need to initialize it at runtime in your entry file. This is how you can do it:
require('offline-plugin/runtime').install();
ES6/Babel/TypeScript
import * as OfflinePluginRuntime from 'offline-plugin/runtime';
OfflinePluginRuntime.install();
For more details of usage with
TypeScript
see here
Runtime has following methods:
Starts installation flow for ServiceWorker
/AppCache
it's safe and must be called each time your page loads (i.e. do not wrap it into any conditions).
Used to apply update for existing installation. See install
options below.
Performs check for updates of new ServiceWorker
/AppCache
.
Runtime install
accepts 1 optional argument, options
object. Right now you can use following runtime options:
(right now install()
accepts only Events and doesn't have any runtime configuration options)
Note: To use events, they must be explicitly enabled for each tool (ServiceWorker
/AppCache
) in their options.
Event called exactly once when ServiceWorker
or AppCache
is installed. Can be useful to display "App is ready for offline usage"
message.
Not supported for AppCache
Event called when update is found and browsers started updating process. At this moment, some assets are downloading.
Event called when onUpdating
phase finished. All required assets are downloaded at this moment and are ready to be updated. Call runtime.applyUpdate()
to apply update.
Event called when onUpdating
phase failed by some reason. Nothing is downloaded at this moment and current update process in your code should be canceled or ignored.
Event called when update is applied, either by calling runtime.applyUpdate()
or some other way by a browser itself.