2017 © Pedro Peláez
 

magento2-module magento2-serviceworker

A Magento 2 extension that adds Service Worker support.

image

meanbee/magento2-serviceworker

A Magento 2 extension that adds Service Worker support.

  • Tuesday, November 28, 2017
  • by meanbee
  • Repository
  • 9 Watchers
  • 30 Stars
  • 1,315 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 15 Versions
  • 42 % Grown

The README.md

Meanbee_ServiceWorker

A Magento 2 extension that adds Service Worker support., (*1)

Features: * Fully customisable Service Worker script * Cache-first approach for page assets resulting in faster page loads * Offline cache for CMS and catalog pages allowing viewing previously visited pages while in poor network conditions, (*2)

Installation

Add this extension to your Magento installation with Composer:, (*3)

composer require meanbee/magento2-serviceworker

Usage

Configuration

The Service Worker is configured and enabled by default. However, Service Workers require the site to run on HTTPS., (*4)

Features can be customised in Stores > Configuration > General > Web > Service Worker Settings., (*5)

Adding more logic

If the base service worker file doesn't fit all of your needs you can easily add more logic using the layout system, targeting the serviceworker_index_js handle:, (*6)

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="serviceworker">
            <block class="\Meanbee\MoreLogic\Block\Logic" name="morelogic.logic" template="Meanbee_MoreLogic::logic.phtml" />
        </referenceBlock>
    </body>
</page>

FAQ

Why do page assets not appear to be cached when Magento is in default/developer mode?

Magento 2 uses a timestamp version string in the URL for static files to allow busting browser cache when the static content gets updated. In developer mode, this version string is updated for every unique page request. This means that from the browser's perspective, the static assets, such as CSS files, are completely different on each page, even though the content is the same. Therefore, when the assets get cached by the Service Worker in Magento 2 developer mode, they only get cached for that specific page. Production mode only generates the static assets through command line and keeps the version timestamp fixed, so it doesn't experience this issue., (*7)

Development

Setting up a development environment

A Docker development environment is included with the project:, (*8)

docker-compose run --rm cli magento-extension-installer Meanbee_ServiceWorker \
&& docker-compose up -d

npm dependencies

The extension uses npm to manage some of its web dependencies. Dependencies are installed and updated using npm, then copied into the src/ directory using an npm script. To update the web dependencies, run:, (*9)

docker-compose run --rm node npm update
docker-compose run --rm node npm run build

Testing Service Workers on Chrome

Chrome is very strict about security and only allows Service Workers on localhost, or on an HTTPS site with a valid certificate. To bypass these restrictions for testing, use the --ignore-certificate-errors and --unsafely-treat-insecure-origin-as-secure flags to run a less secure copy of Chrome:, (*10)

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
    --user-data-dir=/tmp/chrome \
    --ignore-certificate-errors \
    --unsafely-treat-insecure-origin-as-secure=https://m2-meanbee-serviceworker.docker/

The Versions

28/11 2017

dev-master

9999999-dev

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^102.0.0
  • magento/module-config ^101.0.0

 

by Tomas Gerulaitis

28/11 2017

2.2.0

2.2.0.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^102.0.0
  • magento/module-config ^101.0.0

 

by Tomas Gerulaitis

28/11 2017

dev-develop

dev-develop

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^102.0.0
  • magento/module-config ^101.0.0

 

by Tomas Gerulaitis

28/11 2017

dev-10-backend-caching

dev-10-backend-caching

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^102.0.0
  • magento/module-config ^101.0.0

 

by Tomas Gerulaitis

28/11 2017

dev-9-m2.2-unserialize-error

dev-9-m2.2-unserialize-error

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^102.0.0
  • magento/module-config ^101.0.0

 

by Tomas Gerulaitis

27/11 2017

2.1.2

2.1.2.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^102.0.0
  • magento/module-config ^101.0.0

 

by Tomas Gerulaitis

27/11 2017

2.1.1

2.1.1.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^101.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^103.0.0
  • magento/module-config ^102.0.0

 

by Tomas Gerulaitis

17/11 2017

2.1.0

2.1.0.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^102.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^103.0.0
  • magento/module-config ^102.0.0

 

by Tomas Gerulaitis

16/11 2017

dev-m2.2-update

dev-m2.2-update

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^102.0.0
  • magento/module-backend ^100.1.1
  • magento/module-cms ^103.0.0
  • magento/module-config ^102.0.0

 

by Tomas Gerulaitis

30/06 2017

dev-punkstar-docs-adding-more-logic

dev-punkstar-docs-adding-more-logic

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^100.1.2
  • magento/module-backend ^100.1.1
  • magento/module-cms ^101.0.2
  • magento/module-config ^100.1.1

 

by Tomas Gerulaitis

20/06 2017

2.0.0

2.0.0.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^100.1.2
  • magento/module-backend ^100.1.1
  • magento/module-cms ^101.0.2
  • magento/module-config ^100.1.1

 

by Tomas Gerulaitis

14/06 2017

dev-4-extension-support

dev-4-extension-support

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^100.1.2
  • magento/module-backend ^100.1.1
  • magento/module-config ^100.1.1
  • magento/module-cms ^101.0.2

 

by Tomas Gerulaitis

07/06 2017

1.1.0

1.1.0.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^100.1.2
  • magento/module-backend ^100.1.1
  • magento/module-cms ^101.0.2
  • magento/module-config ^100.1.1

 

by Tomas Gerulaitis

10/03 2017

dev-1-magento-2.1.2-compatibility

dev-1-magento-2.1.2-compatibility

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^100.1.2
  • magento/module-backend ^100.1.1
  • magento/module-config ^100.1.1
  • magento/module-cms ^101.0.2

 

by Tomas Gerulaitis

31/01 2017

1.0.0

1.0.0.0

A Magento 2 extension that adds Service Worker support.

  Sources   Download

MIT

The Requires

  • magento/framework ^100.1.2
  • magento/module-backend ^100.1.2
  • magento/module-cms ^101.0.3
  • magento/module-config ^100.1.2

 

by Tomas Gerulaitis