Service workers are an exciting new web browser feature that provides progressive web apps with app-like superpowers to work offline or receive push notifications.
Mobify’s service worker must be installed on your website to unlock the full potential of the Mobify Platform.
NOTE: Mobify provides a cartridge for Salesforce Commerce Cloud (formerly Demandware) to simplify installation.
Installing the worker #
- Find the code for your worker in your project:
web/service-worker-loader.js. Copy its contents.
- On your server, create a worker file called
service-worker-loader.jsthat is available from the root of your domain. If your domain is
example.com, the file must be
- Paste the worker’s code into this file
Verifying the installation #
To verify that the worker is installed correctly:
- Open your browser and navigate to the worker over HTTPS. If your domain is
example.com, open https://example.com/service-worker-loader.js.
- Check the worker opens using HTTPS without errors. Service workers are powerful features that only work over secure connections.
- Check the worker is served exactly from the path
/service-worker-loader.jswithout redirection. Redirects break the worker’s scope by changing the URL it is registered from.
- Check that the contents of the worker on your server exactly match the contents of the worker in your project
- Check the worker is served using the Content Type
A working example #
You can see an example of a correctly installed worker by opening this URL in your web browser: https://www.merlinspotions.com/service-worker-loader.js
When does the worker need to be installed? #
If it’s not possible to install the service worker during development, workarounds are possible.
But in production, the service worker must be installed correctly. To get help with installation, contact email@example.com.