Online / Offline
A pop-up when the connection drops and when it is back, pages that open offline with a saved-copy note, and a game that only opens without a connection.
Online / Offline keeps the site useful when a visitor's internet drops. A card says the connection is gone, and the same card says when it is back. While it is gone, the pages the visitor already opened still open from their own device, with a note that it is a saved copy, and Signal Keeper - a small game - is there to pass the time. It works the same in the browser and inside the Mobile Apps phone and TV apps.
Switching it on
Online / Offline is a free plugin and works with every licence. Switch it on at Admin → Plugins. The menu then shows Online / Offline (admin/plugin.php?code=offline-mode). There is nothing else to set up: it starts with the pop-up, the game and offline browsing on.
The site must run on https (or be opened as localhost): browsers run service workers only there.
What visitors see
- You're offline - a card at the top of the page (on a phone it rises from the bottom), with Play a game while you wait.
- You're back online - the same card, green, which goes by itself after a few seconds.
- A page opened before opens offline with a small note at the bottom: Offline - showing a saved copy from …. On a watch page the note adds that the video plays when the connection is back.
- An address never opened on that device answers with the offline page: This page was not saved on this device for offline use yet, Try again, Back to the site, and the game.
- Signal Keeper (
/plugins/offline-mode/game): turn the dish with the arrow keys, the mouse or a finger, catch messages, likes and signal bars, dodge the static. It opens only while there is no connection; online, its page shows a card saying so. If the network comes back during a game, it pauses and asks keep playing?.
The settings
What is on
- The pop-up - the offline and back-online card.
- The game - Signal Keeper, its page and the link in the pop-up.
- Let it play online too - off by default: the game is for the time without a connection.
- Offline browsing - pages a visitor opened, and the pages listed below, are kept in their browser.
- Pictures too - thumbnails, avatars and channel art seen on those pages.
Where it sits, its colour - Top, in the middle, Bottom, in the middle, Top right or Bottom left on a computer screen; a preview follows the choice. Tick A colour of its own to pick one, otherwise the site's brand colour is used.
The words - the titles and texts of both cards. Leave a box empty for the default words.
How much is kept - Pictures, at most (MB) (5-500, the oldest go first), Pages, at most (10-500), The last pages a visitor opened, kept fresh (0-30).
Pages kept for every visitor - one address per line, such as / or /trending. They are fetched a few seconds after a visitor opens any page. The offline page, the game and the site's own files are always kept.
Never kept - the built-in list (the panel, signing in, money, the upload page, the API, streams and downloads, live pages, anything that is not a plain page read, addresses that carry a token or key) plus your own prefixes. End a line with $ for that one page only.
Clear for everyone - every browser throws its saved pages and pictures away the next time it checks the site. Use it after a big change to the site's look.
With Mobile Apps
The site has one service worker. When Mobile Apps is on, its pages register this plugin's worker, and its own worker address answers with the same worker, so the phone app, the TV app and the browser behave the same. The app's files stay kept. Switch Online / Offline off and Mobile Apps' own worker is back; this plugin's worker removes its saved copies and unregisters itself.
For developers
offline_precache(array $urls)- more addresses every visitor's worker keeps.offline_never(array $prefixes)- more path prefixes it must never keep.service_worker_urlandservice_worker_js- how the two plugins share one worker.
Honest limits
- Videos are not kept: a video is far too large for a browser's storage. Its page opens offline; the video plays when the connection is back.
- Nothing typed offline (a comment, a like, an upload) is kept to send later; those need the connection.
- A page shows what it showed when it was saved: counts, comments and notifications are as old as the note says.
- Browsers give each site a share of the disk; a browser short of space may clear the copies by itself.