Skip to content

Commit

Permalink
Merge pull request #9 from souldanger/version-0.0.7
Browse files Browse the repository at this point in the history
Version 0.0.7.prerelease
  • Loading branch information
souldanger authored Jul 11, 2019
2 parents 63b687f + 05cf8db commit f8497f6
Show file tree
Hide file tree
Showing 69 changed files with 10,682 additions and 149 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Auto detect text files and perform LF normalization
* text=auto

# Ignore all test and documentation with “export-ignore”.
.gitattributes export-ignore
.gitignore export-ignore
CHANGELOG.md export-ignore
README.md export-ignore
LICENSE export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*.gem
*.rbc
/.config
/coverage/
Expand All @@ -9,6 +8,8 @@
/test/tmp/
/test/version_tmp/
/tmp/
.gitignore


# Used by dotenv library to load environment variables.
# .env
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ upgrade library to Workbox version 4.3.0 - see fixes & updates [here](https://gi

upgrade library to Workbox version 4.3.1 - see fixes & updates [here](https://github.com/GoogleChrome/workbox/releases/tag/v4.3.1)

---

# 0.0.7.prerelease

upgrade library to Workbox version 5.0.0_pre-release
86 changes: 0 additions & 86 deletions MIGRATE.md

This file was deleted.

134 changes: 77 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@
[![MIT license](http://img.shields.io/badge/license-MIT-orange.svg)](http://opensource.org/licenses/MIT)
# Jekyll PWA Workbox Plugin

This Jekyll plugin makes your PWA / Website available offline and allows you to install on desktop or mobile*.
It uses a Workbox service worker, generates and injects a precache list into it and takes care of the registration process in a secure way.
A Jekyll plugin that makes your PWA / Website available offline and lets you install on desktop and mobile*.
It generates and injects a precache list into a [Workbox][workbox] service worker and handles the registration process in a secure way.
_* does not fully work with iOS/Safari to date_

The plugin was originally developed by Pan Yuqi and sekiyika from [Lavas Project](https://github.com/lavas-project/jekyll-pwa).
It is pretty much the same, except for:
The plugin was originally developed by [Lavas Project](https://github.com/lavas-project/jekyll-pwa). It is pretty much the same, except for:
- the starter process is initiated from a js file to allow for ```script-src 'self';``` in your CSP, rather than ```unsafe-inline```.
- serves `sw-register.js` minified for better auditing results.
- serves `sw-register.js` minified.

---

**PLEASE NOTE** we're now using **Workbox version 4** and therefore you'll need to update your `service-worker.js` as below.
This plugin supports the PRE-RELEASE of **Workbox version 5.0.0** *.

Google has developed a series of tools, these are available on their [Workbox](https://developers.google.com/web/tools/workbox/) page.
If you use Webpack or Gulp as your build tool, you can easily generate a service worker with these tools.
As we do not want to use npm, we would like to precache and make posts and pages available offline, even if they have never been visited before.
Therefore we are integrating this function in the Jekyll build process.

**IMPORTANT** This plugin supports **Workbox version 4.3.1**. If you are still using v1.x.x, you will have to migrate.
A migration guide is available [here](./MIGRATE.md).
The API of Workbox v4 has changed a lot compared to previous releases, some more powerful functions have been added too.
_* in case you have been using a previous Workbox version (i.e. 3 or older), please see migration instructions [here](https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v3)._

There are various tools available on the [Workbox tools](https://developers.google.com/web/tools/workbox/) page, that let you easily generate a service worker with Webpack or Gulp as your build tool.

We do not use `npm` and therefore integrate this function in the Jekyll build process to precache and make posts/pages available offline, even if they have never been visited before.

---

## Prerequisites

### Web App Manifest

A `manifest.json` is required to experience the full features of your PWA.

In case you do not have one already, please read the following about creating and adding a [manifest.json](https://developers.google.com/web/fundamentals/web-app-manifest/).
Add it to the root directory of your project and Jekyll will deploy it to `_site` when your PWA / Website builds.

Use `Chrome DevTools > Application` for debugging/testing.


## Installation
Expand All @@ -40,7 +49,7 @@ source 'https://rubygems.org'
gem 'jekyll'

group :jekyll_plugins do
gem 'jekyll-pwa-workbox'
gem "jekyll-pwa-workbox", "~> 0.0.7.prerelease"
end
```

Expand Down Expand Up @@ -91,44 +100,20 @@ precache_glob_patterns | Patterns of precache. [Workbox Config](https://devel
precache_glob_ignores | Ignores of precache. [Workbox Config](https://developers.google.com/web/tools/workbox/get-started/webpack#optional-config)
precache_recent_posts_num | Number of recent posts to precache.

We handle precache and runtime cache with the help of Google Workbox in service worker.

### Start the Service Worker
We handle precache and runtime cache with the help of [Workbox][workbox] in service worker.

Add the following two blocks to an existing JS file:

*this must be at the start of your JS file, before any other code, so that the script-src can be generated*
```
---
layout: null
---
```
*this snippet can live anywhere in your JS file (i.e. app.js)*
```javascript
window.onload = function () {
var script = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
script.async = true;
script.src = '{{'sw-register.js'|relative_url}}?v=' + Date.now();
firstScript.parentNode.insertBefore(script, firstScript);
};
```

OR use any of these files to start the service worker registration:
- [pwa-1.0.js](./pwa-1.0.js)
- [pwa-1.0.min.js](./pwa-1.0.min.js)
## Service Worker

### Write your own

### Write your own Service Worker
Create a `service-worker.js` in the root path of your Jekyll project. The source file's path can be adjusted with the `sw_src_filepath` option.

Create a `service-worker.js` in the root path of your Jekyll project.
You can change the source file's path with `sw_src_filepath` option.
You can write your own service worker with [Workbox APIs](https://developers.google.com/web/tools/workbox/reference-docs/latest/).

Now you can write your own Service Worker with [Workbox APIs](https://developers.google.com/web/tools/workbox/reference-docs/latest/).
### Basic example

Here's an exmaple of a **NEW** [service-worker.js](./service-worker.js) for **Workbox v4.x.x** or create one yourself:
Here is a basic example of [service-worker.js](./service-worker.js):
```javascript
// service-worker.js
Expand Down Expand Up @@ -172,26 +157,61 @@ workbox.routing.registerRoute(
);
```

## Note

### Generate a manifest.json?
## Register the Service Worker

Add the following two blocks to an existing JS file (i.e. app.js):

*this must be at the start of your JS file, before any other code, so that the script-src can be generated*
```
---
layout: null
---
```


*this snippet can live anywhere in your JS file (i.e. app.js)*
```javascript
window.onload = function () {
var script = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
script.async = true;
script.src = '{{'sw-register.js'|relative_url}}?v=' + Date.now();
firstScript.parentNode.insertBefore(script, firstScript);
};
```

OR use any of these files to start the service worker registration:
- [pwa-1.0.js](./pwa-1.0.js)
- [pwa-1.0.min.js](./pwa-1.0.min.js)


DONE - use `Chrome DevTools`for debugging/testing.

---

## Notes

### Updates / Manual Refresh

This plugin won't generate a [manifest.json](https://developer.mozilla.org/en-US/docs/Web/Manifest). If you want to support this PWA feature, just add one in your root directory and Jekyll will copy it to `_site`.
When the PWA / Website updates, the service worker will go into the `install` stage and request the newest resources, but the user must refresh current page manually so that these updates can be applied.
This can be done by notifying the user with a toast such as `website updated - please refresh the page manually` or whatever else fits your needs.

### When my site updates...
### Workbox Plugins

As the service worker has precached our assets such as `index.html`, JS files and other static files, we should notify user when our site has something changed. When these updates happen, the service worker will go into the `install` stage and request the newest resources, but the user must refresh current page so that these updates can be applied. A normal solution is showing a toast with the following text: `This site has changed, please refresh current page manually.`.
Workbox also comes with a set of plugins, details of how to use these can be found in the [Workbox Guide - Using Plugins](https://developers.google.com/web/tools/workbox/guides/using-plugins)

This plugin will dispatch a custom event called `sw.update` when the service worker has finished the update work. So in your site, you can choose to listen this event and popup a toast to remind users refreshing current page.
## Contribute

# Contribute
Fork this repository, make your changes and then issue a pull request. If you find a bug or if you have new ideas, please file an issue in our [bug tracker](https://github.com/souldanger/jekyll-pwa-workbox/issues).

Fork this repository, make your changes and then issue a pull request. If you find bugs or have new ideas that you do not want to implement yourself, file a bug report.
## Copyright

# Copyright
Copyright © 2019 souldanger

Copyright © 2019 souldanger, Pan Yuqi, sekiyika
Copyright © 2017 Pan Yuqi, Xing Peng

License: MIT
License: [MIT](https://github.com/souldanger/jekyll-pwa-workbox/blob/master/LICENSE)

[ruby-gem]: https://rubygems.org/gems/jekyll-pwa-workbox
[workbox]: https://developers.google.com/web/tools/workbox/
Binary file added jekyll-pwa-workbox-0.0.7.prerelease.gem
Binary file not shown.
14 changes: 9 additions & 5 deletions jekyll-pwa-workbox.gemspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
Gem::Specification.new do |s|
s.name = 'jekyll-pwa-workbox'
s.version = '0.0.7.prerelease'
s.date = '2019-07-11'
s.version = '0.0.6'
s.date = '2019-05-08'
s.summary = "PWA Workbox Service Worker for Jekyll."
s.description = "This Jekyll plugin makes your PWA / Website available offline and allows you to install on desktop or mobile.
It uses a Workbox v4 service worker, generates and injects a precache list into it and takes care of the registration process in a secure way."
s.authors = ['souldanger', 'Pan Yuqi', 'sekiyika']
s.email = ['sammyoneski@outlook.com', 'pyqiverson@gmail.com', 'pengxing5501854@gmail.com']
s.description = "A Jekyll plugin that makes your PWA / Website available offline and lets you install on desktop and mobile.
It generates and injects a precache list into a Workbox v5 service worker and handles the registration process in a secure way."
s.authors = ['souldanger']
s.email = ['souldanger.industries@gmail.com']
s.files = Dir["lib/*.rb"] + Dir["lib/vendor/**/*"]
s.homepage = 'https://github.com/souldanger/jekyll-pwa-workbox'
s.license = 'MIT'
s.metadata = {
"bug_tracker_uri" => "https://github.com/souldanger/jekyll-pwa-workbox/issues",
"changelog_uri" => "https://github.com/souldanger/jekyll-pwa-workbox/blob/master/CHANGELOG.md",
"documentation_uri" => "https://github.com/souldanger/jekyll-pwa-workbox/blob/master/README.md",
"changelog_uri" => "https://github.com/souldanger/jekyll-pwa-workbox/blob/master/changelog.md",
"documentation_uri" => "https://github.com/souldanger/jekyll-pwa-workbox",
"homepage_uri" => "https://github.com/souldanger/jekyll-pwa-workbox",
"source_code_uri" => "https://github.com/souldanger/jekyll-pwa-workbox",
"source_code_uri" => "https://github.com/souldanger/jekyll-pwa-workbox/releases",
}
end
Loading

0 comments on commit f8497f6

Please sign in to comment.