Skip to content

Commit 106c981

Browse files
committed
feat: add option to turn off PWA (#527)
1 parent d127183 commit 106c981

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

_config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ assets:
115115
# only works if `assets.self_host.enabled` is 'true'
116116
env: # [development|production]
117117

118+
pwa:
119+
enabled: true # the option for PWA feature
120+
118121
paginate: 10
119122

120123
# ------------ The following options are not recommended to be modified ------------------

_includes/js-selector.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@
9090

9191
{% if jekyll.environment == 'production' %}
9292
<!-- PWA -->
93-
<script defer src="{{ '/app.js' | relative_url }}"></script>
93+
{% if site.pwa.enabled %}
94+
<script defer src="{{ '/app.js' | relative_url }}"></script>
95+
{% else %}
96+
<script defer src="{{ '/unregister.js' | relative_url }}"></script>
97+
{% endif %}
9498

9599
<!-- GA -->
96100
{% if site.google_analytics.id != empty and site.google_analytics.id %}

_layouts/default.html

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,22 @@
4848
<i class="fas fa-angle-up"></i>
4949
</a>
5050

51-
<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
52-
data-animation="true" data-autohide="false">
53-
<div class="toast-header">
54-
<button type="button" class="ml-2 ml-auto close" data-dismiss="toast" aria-label="Close">
55-
<span aria-hidden="true">&times;</span>
56-
</button>
51+
{% if site.pwa.enabled %}
52+
<div id="notification" class="toast" role="alert" aria-live="assertive" aria-atomic="true"
53+
data-animation="true" data-autohide="false">
54+
<div class="toast-header">
55+
<button type="button" class="ml-2 ml-auto close" data-dismiss="toast" aria-label="Close">
56+
<span aria-hidden="true">&times;</span>
57+
</button>
58+
</div>
59+
<div class="toast-body text-center pt-0">
60+
<p class="pl-2 pr-2 mb-3">{{ site.data.locales[lang].notification.update_found }}</p>
61+
<button type="button" class="btn btn-primary" aria-label="Update">
62+
{{ site.data.locales[lang].notification.update }}
63+
</button>
64+
</div>
5765
</div>
58-
<div class="toast-body text-center pt-0">
59-
<p class="pl-2 pr-2 mb-3">{{ site.data.locales[lang].notification.update_found }}</p>
60-
<button type="button" class="btn btn-primary" aria-label="Update">
61-
{{ site.data.locales[lang].notification.update }}
62-
</button>
63-
</div>
64-
</div>
66+
{% endif %}
6567

6668
{% include search-loader.html %}
6769

assets/js/pwa/unregister.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
layout: compress
3+
permalink: '/unregister.js'
4+
---
5+
6+
if ('serviceWorker' in navigator) {
7+
navigator.serviceWorker.getRegistrations().then((registrations) => {
8+
for (let reg of registrations) {
9+
reg.unregister();
10+
}
11+
});
12+
}

0 commit comments

Comments
 (0)