GithubHelp home page GithubHelp logo

processwire-serviceworker's Introduction

ProcessWire ServiceWorker

This is a simple module that provides a Service Worker for viewing Processwire pages offline. It’s heavily based on the work of Jeremy Keith – thank you Jeremy!

How it works

When a people visit your site and their browser supports the use of service workers, a small JavaScript (the service worker) gets installed in their browser. The script sits in the background, intercepts network requests and then does the following:

If the requested resource is an HTML document:

  1. try and fetch the page from the network
  2. if that doesn’t work, try and serve the page from the cache
  3. if that also fails, fall back to a specified offline page

If the requested resource is a file:

  1. try and serve the file from the cache (if available)
  2. if the file is not in the cache, try and request it from the network
  3. if everything else fails and the requested file is an image, show a placeholder

Installation

Copy the module directory to /site/modules/, then in Processwire Admin go to Modules > Site > Add New, click “Refresh” and install the ServiceWorker module.

During the installation, the module copies a PHP file (serviceworker.js.php) to your Processwire root directory. This file is served as JavaScript and contains the actual Service Worker.

Configuration

The module offers a few configuration options:

  • Current cache version: cache version number. You can force the service worker to upgrade the cached pages and static assets by bumping this to a higher number. Also, the module bumps the version automatically when one of the configured offline pages is saved.
  • Max. pages in cache: the number of pages that can live in the page cache
  • Max. images in cache: the number of images that can live in the image cache
  • Offline page: a page that is served when the user agent has no connection to the network.
  • Additional pages to cache: other pages that are cached upfront when the service worker gets installed.
  • Static assets to cache: any static assets that need to be cached when the service worker gets installed.

Usage

To include the service worker in your templates use <?php $modules->get('ServiceWorker')->renderJavaScript(); ?>. Right before the closing </body> tag is a good place to put it.

License

Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication

http://creativecommons.org/publicdomain/zero/1.0/

processwire-serviceworker's People

Contributors

johannesdachsel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

pwfoo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.