Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: azu <[email protected]>
  • Loading branch information
azu committed Nov 29, 2023
1 parent 5dbf949 commit 58ad68e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
10 changes: 0 additions & 10 deletions source/_layouts/website/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,6 @@ <h2 class="book-header-title-h" title="JavaScript Primer - 迷わないための
setTimeout(() => console.clear(), 1000);
});
});
// unregister old service worker
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (const registration of registrations) {
registration.unregister();
}
}).catch(function(err) {
console.error(new Error("Can not getRegistrations", {
cause: err
}));
});
</script>
{% endblock %}

26 changes: 10 additions & 16 deletions source/_layouts/website/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,17 @@
<meta name="theme-color" content="#ffffff">
<link rel="manifest" href="{{ "/manifest.json"|resolveFile }}">
<script>
if ("serviceWorker" in navigator) {
const isLocalhost = Boolean(
// preview
/netlify.com/.test(window.location.hostname) ||
// local
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === "[::1]" ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
if (!isLocalhost) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("{{ '/sw.js'|resolveFile }}");
});
// unregister old service worker(remove workbox)
// https://github.com/asciidwango/js-primer/pull/1701
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (const registration of registrations) {
registration.unregister();
}
}
}).catch(function(err) {
console.error(new Error("Can not getRegistrations", {
cause: err
}));
});
</script>
{% endblock %}
{% block book_inner %} {{ super() }}
Expand Down

0 comments on commit 58ad68e

Please sign in to comment.