CTRL->pwa->get_sw(); $scope = $this->CTRL->pwa->get_sw_scope(); // verify service worker if (isset($options['pwa']) && intval($options['pwa']) === 1) { $this->pwa->install_serviceworker(); } // asset cache policy $asset_policy = (isset($options['pwa_cache_assets_policy']) && is_array($options['pwa_cache_assets_policy'])) ? $options['pwa_cache_assets_policy'] : $this->CTRL->pwa->get_sw_default_policy(); ?>

Google Bot

Google has been promoting Progressive Web Apps (PWA) as the future of the internet: a combination of the flexability and openness of the existing web with the user experience advantages of native mobile apps. In essence: a mobile app that can be indexed by Google and that can be managed by WordPress.

Google provides an extensive test called Lighthouse that tests for validity against the key qualities of a Progressive Web App: performance, accessibility, and more.

This tool enables to score 100 / 100 / 100 / 100 in the lighthouse test and validate a website as Progressive Web App for improved mobile user experiences and findability.

At the core of the features of a Progressive Web App is a HTML5 Service Worker. It's not supported by Internet Explorer and Opera (browser compatibility).

>
Enable PWA

Enable PWA functionality in browsers that support Service Worker.

Unchecking this option enables to combine the PWA Service Worker with other service workers, for example for Push Notifications. If you want to load the PWA Service Worker using importScripts use the file /.

Unregister the PWA Service Worker for visitors.

 
 Service Worker Scope

Enter an optional scope for the service worker, e.g. /blog/. The scope restricts the PWA functionality to a path.

 
 Push Notification API

The PWA Service Worker supports sending Push Notifications (documentation). The API is Abtf.push(title,options) (show example)

Tip: For debugging the Service Worker see: chrome://serviceworker-internals (copy in the address bar)

Cache Pages

Cache HTML pages in the service worker. This option enables to make a website available offline.

 
 HTML Cache Strategy

By default HTML pages are fetched from the network with the cache as fallback when the network fails. Select the Cache First strategy to serve pages from cache with the network as backup. Select the On demand strategy to use a Cache First strategy with a manual (event based) cache storage (e.g. "click to read this page offline"). The API is Abtf.offline(url); which can also be used for precaching. (show example)

 
 HTML Cache Include List

Enter (parts of) page URL's to cache, e.g. category/ to match all pages in a category.

Preload on Mouse Down

Start preloading navigation requests in the Service Worker on mouse down. Older mobile devices including iOS8 have a 300ms click delay which is a lot of time wasted for navigation clicks. An average mouse click also has a 200-500ms delay before navigation starts. This feature enables to start preloading a page in the Service Worker on mouse down/touch start to make use of the otherwise wasted delay.

 Offline Page

Enter an URL or absolute path to a HTML page to display when the network is offline and when the requested page is not available in cache.

Cache Assets

Cache assets such as scripts and styles. Use a request and/or response filter to apply a cache strategy and enable or disable caching for specific assets.

JSON editor Star
CSS online/offline class

Add the class offline to <body> based on HTML5 online/offline events. This feature enables to add a user friendly notice via CSS when the connection is offline.

Cache Size

Maximum cache entries to maintain. The default is 1000.

Cache Version

Optionally enter a cache version. This feature enables to invalidate existing caches.

Cache Preload

Enter URLs or absolute path's to preload for offline availability, e.g. /path/to/page.html or /path/to/image.jpg.

Web App Manifest 

The Web App Manifest is a JSON document that enables to control how a website app appears to the user in areas where they would expect to see apps. It is required to validate as Google PWA. (W3C documentation)

' . trailingslashit(home_url()) . 'manifest.json not found. Add the file to the root of your WordPress installation and make it writeable.
'; } elseif (!is_writeable($manifest)) { print '

' . trailingslashit(home_url()) . 'manifest.json is not writeable. Please make the file writeale for WordPress (PHP) to enable online editing and automatic serviceworker configuration.

'; } else { $json = file_get_contents(trailingslashit(ABSPATH) . 'manifest.json'); $manifestjson = @json_decode(trim($json), true); if (!is_array($manifestjson)) { $manifestjson = array(); print '
' . trailingslashit(home_url()) . 'manifest.json does not contain valid JSON.
'; } ?>
JSON editor Star

There are several online tools that can help with Web App Manifest creation. https://app-manifest.firebaseapp.com/ is a simple one. Search Google for more creators.

Update manifest.json when saving settings.

Add a link to manifest.json in the <head> of the page.

Web App Meta

Enter Web App related meta tags to include in the <head> of the page. (documentation). There are many Web App Meta Generators that enable to fine tune the settings for an optimal mobile representation.

Tip: Use the Google Chrome Application > Manifest tab to debug the settings and to simulate Add to homescreen.