Skip to content
This repository was archived by the owner on Apr 16, 2022. It is now read-only.

Commit 8a3b99d

Browse files
committed
feat: use Workbox to enable offline content
1 parent 4f59c0c commit 8a3b99d

File tree

5 files changed

+5434
-12
lines changed

5 files changed

+5434
-12
lines changed

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ plugins:
5656
# - git-revision-date-localized
5757
- minify:
5858
minify_html: true
59+
minify_js: true
5960

6061
# Google Analytics
6162
google_analytics:

overrides/main.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{% extends "base.html" %}
2+
3+
{% block libs %}
4+
<!-- From https://developers.google.com/web/tools/workbox/guides/get-started#create_and_register_a_service_worker_file -->
5+
<script>
6+
// Check that service workers are supported
7+
if ("serviceWorker" in navigator) {
8+
// Use the window load event to keep the page load performant
9+
window.addEventListener("load", () =>
10+
navigator.serviceWorker.register("/sw.js")
11+
);
12+
}
13+
</script>
14+
{% endblock %}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"name": "docs",
33
"devDependencies": {
4-
"prettier": "2.0.5"
4+
"prettier": "2.0.5",
5+
"workbox-cli": "^5.1.3"
56
},
67
"scripts": {
7-
"style": "prettier --check ."
8+
"style": "prettier --check .",
9+
"sw:gen": "workbox generateSW workbox-config.js"
810
}
911
}

workbox-config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
"globDirectory": "site/",
3+
"globPatterns": [
4+
"**/*.{html,png,js,css,Identifier,txt,webmanifest,json,xml,gz}"
5+
],
6+
"swDest": "site/sw.js"
7+
};

0 commit comments

Comments
 (0)