Sha256: b59302e7992bf84f5ea48f962e6c6524daff21804513c23755f200d5b41ab83a

Contents?: true

Size: 1.02 KB

Versions: 62

Compression:

Stored size: 1.02 KB

Contents

/**
 * On PWA installation, pre-cache the assets & offline page
 */
self.addEventListener('install', function (event) {
    event.waitUntil(
        caches.open('pwa_cache').then(function (cache) {
          return cache.addAll([
            '<%= image_path("workarea/storefront/logo.png") %>',
            '<%= stylesheet_path("workarea/storefront/application.css") %>',
            '<%= javascript_path("workarea/storefront/head.js") %>',
            '<%= javascript_path("workarea/storefront/application.js") %>',
            '/offline'
          ]);
        })
    );
});

/**
 * On PWA fetch, serve the offline system content page if the connection fails
 */
self.addEventListener('fetch', function (event) {
    if (event.request.mode !== 'navigate') { return; }
    if (event.request.method !== 'GET') { return; }
    if ( ! event.request.headers.get('accept').includes('text/html')) { return; }

    event.respondWith(
        fetch(event.request).catch(function () {
            return caches.match('/offline');
        })
    );
});

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-storefront-3.4.27 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.5.4 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.26 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.5.3 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.25 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.5.2 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.24 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.5.1 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.23 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.22 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.5.0 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.21 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.5.0.beta.1 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.20 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.19 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.18 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.17 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.16 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.15 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb
workarea-storefront-3.4.14 app/assets/javascripts/workarea/storefront/serviceworkers/pwa_cache.js.erb