silverstripe-progressivewebapp/README.md

34 lines
978 B
Markdown
Raw Permalink Normal View History

2018-06-24 15:51:50 +02:00
# SilverStripe Progressive Web App
Tools to add progressive web app functionality to your silverstripe website
2020-04-01 21:42:13 +02:00
And make it available offline
2018-06-24 15:51:50 +02:00
## Installation
```
2020-04-01 21:42:13 +02:00
composer require a2nt/silverstripe-progressivewebapp
2018-06-24 15:51:50 +02:00
```
## Usage
2018-07-04 12:36:46 +02:00
- Install the module, run dev/build and fill in the settings in the siteconfig
2020-04-02 01:41:49 +02:00
- Add js to register the service worker (example can be found at client/src/app.js)
2018-07-04 12:36:46 +02:00
```
2020-04-01 21:42:13 +02:00
if ('serviceWorker' in navigator) {
2020-04-02 21:44:18 +02:00
var baseHref = (document.getElementsByTagName('base')[0] || {}).href;
var version = (document.querySelector('meta[name="swversion"]') || {})
.content;
if (baseHref) {
navigator.serviceWorker
.register(baseHref + 'sw.js?v=' + version)
.then(() => {
console.log('SW: Registered');
});
}
2020-04-01 21:42:13 +02:00
}
2018-07-04 12:36:46 +02:00
```
- Add the following tags to the head of your website
```
2020-04-01 21:42:13 +02:00
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="{$BaseHref}manifest.json" />
2020-04-02 14:13:49 +02:00
<meta name="swversion" content="{$SWVersion}" />
2018-07-05 18:04:16 +02:00
```