Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (31 sloc) 1.34 KB
{{ if and .Site.Params.enableServiceWorker (eq hugo.Environment "production") }}
{{- partial "components/relative-url.html" (dict "Deliver" . "filename" "sw.js") -}}
{{- $url := .Scratch.Get "url" }}
<div class="app-refresh" id="app-refresh">
<div class="app-refresh-wrap" onclick="location.reload()">
<label>{{ i18n "serviceWorkerUpdatedText" }}</label>
<span>{{ i18n "serviceWorkerUpdatedAction" }}</span>
</div>
</div>
<script>
if('serviceWorker' in navigator) {
{{ printf `navigator.serviceWorker.register('%s')` $url | safeJS }}
.then(reg => {
reg.addEventListener('updatefound', () => {
newWorker = reg.installing;
newWorker.addEventListener('statechange', () => {
if (newWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
showNotification();
}
}
});
});
});
}
function showNotification() {
document.querySelector('meta[name=theme-color]').content = '#000';
document.getElementById('app-refresh').className += ' app-refresh-show';
}
</script>
{{ end }}
You can’t perform that action at this time.