I develop the static website francoscarpa.com using Eleventy. This website uses a service worker to provide offline capabilities to the user. All my pages are rendered through this template:
<!DOCTYPE html>
<html>
<head>...</head>
<body>
...
<footer>...</footer>
{% include "swRegistration.html" %}
</body>
</html>
swRegistration.html
has this content:
<script>
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
...
navigator.serviceWorker.register("/sw.js");
});
}
</script>
It basically lets me use the service worker. The content of the sw.js
file is this:
const CACHE_NAME = "static12";
const STATIC_FILES = [ ... ]; // the resources to cache
self.addEventListener("install", function (event) { ... });
self.addEventListener("activate", function (event) { ... });
self.addEventListener("fetch", function (event) { ... });
What I don’t understand is why the service worker caches the resources even when I disable the {% include "swRegistration.html" %}
line from the generated HTML files:
<html>
<head>...</head>
<body>
...
<footer>...</footer>
<!-- {% include "swRegistration.html" %} -->
</body>
</html>
If I comment that line out, the rendered HTML pages correctly don’t show it and when I start Eleventy’s live-reload web server during development, the line is not present:
but analyzing the page with Firefox’s Inspector, I see the static12
cache is still there after every page refresh, even after I manually delete it: