{"id":13612466,"url":"https://github.com/bmeurer/jekyll-workbox-plugin","last_synced_at":"2025-07-14T10:33:51.041Z","repository":{"id":56878990,"uuid":"160660229","full_name":"bmeurer/jekyll-workbox-plugin","owner":"bmeurer","description":"👨‍🔧Jekyll integration with Google Workbox to create Service Worker automatically.","archived":false,"fork":false,"pushed_at":"2019-02-01T08:39:52.000Z","size":25,"stargazers_count":14,"open_issues_count":2,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T01:41:23.354Z","etag":null,"topics":["jekyll","jekyll-plugin","ruby","workbox"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bmeurer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-06T10:43:18.000Z","updated_at":"2022-01-31T21:49:46.000Z","dependencies_parsed_at":"2022-08-20T11:40:28.116Z","dependency_job_id":null,"html_url":"https://github.com/bmeurer/jekyll-workbox-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bmeurer/jekyll-workbox-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmeurer%2Fjekyll-workbox-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmeurer%2Fjekyll-workbox-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmeurer%2Fjekyll-workbox-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmeurer%2Fjekyll-workbox-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmeurer","download_url":"https://codeload.github.com/bmeurer/jekyll-workbox-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmeurer%2Fjekyll-workbox-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265280820,"owners_count":23739857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jekyll","jekyll-plugin","ruby","workbox"],"created_at":"2024-08-01T20:00:30.320Z","updated_at":"2025-07-14T10:33:50.960Z","avatar_url":"https://github.com/bmeurer.png","language":"Ruby","funding_links":[],"categories":["Other","Ruby"],"sub_categories":[],"readme":"# Jekyll Workbox Plugin [![Gem Version](https://badge.fury.io/rb/jekyll-workbox-plugin.png)](http://badge.fury.io/rb/jekyll-workbox-plugin)\n\n\u003e Google Workbox integration for Jekyll\n\nThis plugin provides integration with [Google Workbox](https://developers.google.com/web/tools/workbox/) for the [Jekyll](https://jekyllrb.com/) static site generator. It generates a service worker and provides precache integration with artifacts managed by Jekyll.\n\nThis plugin provides [workbox-cli](https://developers.google.com/web/tools/workbox/modules/workbox-cli) like functionality for projects using Jekyll. It's based on the [Jekyll PWA Plugin](https://github.com/lavas-project/jekyll-pwa), but it tries to be less clever than that, and focuses purely on the Workbox integration.\n\nYou see this plugin in action on [my website](https://benediktmeurer.de), which is built using Jekyll and comes with a service worker for offline capabilities.\n\n## Installation\n\nThis plugin is available as a [RubyGem][ruby-gem].\n\n### Option #1\n\nAdd `gem 'jekyll-workbox-plugin'` to the `jekyll_plugin` group in your `Gemfile`:\n\n```ruby\nsource 'https://rubygems.org'\n\ngem 'jekyll'\n\ngroup :jekyll_plugins do\n  gem 'jekyll-workbox-plugin'\nend\n```\n\nThen run `bundle` to install the gem.\n\n### Option #2\n\nAlternatively, you can also manually install the gem using the following command:\n\n```\n$ gem install jekyll-workbox-plugin\n```\n\nAfter the plugin has been installed successfully, add the following lines to your `_config.yml` in order to tell Jekyll to use the plugin:\n\n```yaml\nplugins:\n- jekyll-workbox-plugin\n```\n\n## Getting Started\n\n### Configuration\n\nAdd the following configuration block to Jekyll's `_config.yml`:\n```yaml\nworkbox:\n  sw_src_filepath: sw.js # Optional\n  sw_dest_filename: sw.js # Optional\n  precache_recent_posts_num: 5 # Optional\n  precache_glob_directory: / # Optional\n  precache_glob_patterns: # Optional\n    - \"{js,css,fonts}/**/*.{js,css,eot,svg,ttf,woff}\"\n    - index.html\n    - \"about.html\": # This entry aliases about/ and contact/ to about.html\n        - about/\n        - contact/\n  precache_glob_ignores: # Optional\n    - \"fonts/**/*\"\n```\n\nParameter                 | Description\n----------                | ------------\nsw_src_filepath           | Filepath of the source service worker. Defaults to `sw.js`\nsw_dest_filename          | Filename of the destination service worker. Defaults to `sw.js`\nprecache_glob_directory   | Directory of precache. [Workbox Config](https://developers.google.com/web/tools/workbox/get-started/webpack#optional-config)\nprecache_glob_patterns    | Patterns of precache. Accepts aliased names pointing to the same file to support pretty permalinks. [Workbox Config](https://developers.google.com/web/tools/workbox/get-started/webpack#optional-config)\nprecache_glob_ignores     | Ignores of precache. [Workbox Config](https://developers.google.com/web/tools/workbox/get-started/webpack#optional-config)\nprecache_recent_posts_num | Number of recent posts to precache.\n\n### Write your own Service Worker\n\nCreate a file `sw.js` in the root path of your Jekyll project. You can change this source file's path with `sw_src_filepath` option if you don't like the default.\n\nNow you can write your own Service Worker with [Workbox APIs](https://developers.google.com/web/tools/workbox/reference-docs/latest/), including a line `workbox.precaching.precacheAndRoute([]);`, which will be re-written by this plugin according to the precache configuration specified in the `_config.yml` file.\n\nHere's what the `sw.js` like in my site.\n```javascript\n// sw.js\n\n// set names for both precache \u0026 runtime cache\nworkbox.core.setCacheNameDetails({\n    prefix: 'benediktmeurer.de',\n    suffix: 'v1',\n    precache: 'precache',\n    runtime: 'runtime-cache'\n});\n\n// let Service Worker take control of pages ASAP\nworkbox.skipWaiting();\nworkbox.clientsClaim();\n\n// default to `networkFirst` strategy\nworkbox.routing.setDefaultHandler(workbox.strategies.networkFirst());\n\n// let Workbox handle our precache list\n// NOTE: This will be populated by jekyll-workbox-plugin.\nworkbox.precaching.precacheAndRoute([]);\n\n// use `Stale-while-revalidate` strategy for images and fonts.\nworkbox.routing.registerRoute(\n    /images/,\n    workbox.strategies.staleWhileRevalidate()\n);\nworkbox.routing.registerRoute(\n    /^https?:\\/\\/fonts\\.googleapis\\.com/,\n    workbox.strategies.staleWhileRevalidate()\n);\n```\n\nMake sure to follow the [Service Worker Checklist](https://developers.google.com/web/tools/workbox/guides/service-worker-checklist) from the Workbox documentation. Insert this snippet in your JavaScript code somewhere:\n\n```js\nif ('serviceWorker' in navigator) {\n  window.addEventListener('load', function() {\n      navigator.serviceWorker.register('/sw.js');\n  });\n}\n```\n\ni.e. put it inline near the closing `\u003c/body\u003e` tag of every page:\n\n```html\n\u003cscript\u003e\n  if ('serviceWorker' in navigator) {\n    window.addEventListener('load', function() {\n        navigator.serviceWorker.register('/sw.js');\n    });\n  }\n\u003c/script\u003e\n```\n\n...or into your JavaScript bundle. And also make sure to set the `Cache-Control` HTTP header to `no-cache` for the `sw.js` file. For example when using [Netlify](https://www.netlify.com) just put this snippet into your `_headers` file:\n\n```\n# _headers\n/sw.js\n  Cache-Control: no-cache\n```\n\nOr if you're using [Firebase](https://firebase.google.com), put something like this into your `firebase.json` file:\n\n```json\n{\n  \"hosting\": {\n    \"headers\": [\n      {\n        \"source\": \"/sw.js\",\n        \"headers\": [{\n          \"key\": \"Cache-Control\",\n          \"value\": \"no-cache\"\n        }]\n      }\n    ]\n  }\n}\n```\n\n# Contribute\n\nJust fork this repository, make changes and submit a pull request, or just file a bug report.\n\n# Copyright\n\nCopyright (c) 2018 Benedikt Meurer.\n\nCopyright (c) 2017 Pan Yuqi.\n\nLicense: MIT\n\n[ruby-gem]: https://rubygems.org/gems/jekyll-workbox-plugin\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmeurer%2Fjekyll-workbox-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmeurer%2Fjekyll-workbox-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmeurer%2Fjekyll-workbox-plugin/lists"}