A swup plugin for making content available offline.
- Preload pages for offline access
- Prevent new network requests while offline
- Display a notification when network status changes
Warning
This plugin is in very early public development. Features and APIs will not be stable for a while, things can and will change.
Install the plugin from npm and import it into your bundle.
npm install @swup/offline-plugin
import SwupOfflinePlugin from '@swup/offline-plugin';
Or include the minified production file from a CDN:
<script src="https://unpkg.com/@swup/offline-plugin@1"></script>
To run this plugin, include an instance in the swup options.
const swup = new Swup({
plugins: [new SwupOfflinePlugin()]
});
Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet.
The plugin creates two new hooks.
Note The visit object might be
undefined
or already settled for these hooks
Fires when the user's device goes offline.
swup.hooks.on('network:offline', () => showOfflineBanner());
Fires when the user's device goes online again.
swup.hooks.on('network:online', () => hideOfflineBanner());