Service Worker (sw.js)
A sample cache-first service worker handling install, activate, and fetch events with an offline fallback — for testing service-worker registration, JS parsers, and PWA tooling.
// sw.js - a sample service worker (cache-first for static assets, network
// fallback, and offline page). Illustrative fixture, not wired to a real app.
const CACHE = "novus-static-v1";
const ASSETS = ["/", "/index.html", "/styles.css", "/app.js", "/offline.html"];
self.addEventListener("install", (event) => {
event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(ASSETS)));
self.skipWaiting();
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))),
),
);
self.clients.claim();
});
self.addEventListener("fetch", (event) => {
const { request } = event;
if (request.method !== "GET") return;
event.respondWith(
caches.match(request).then(
(cached) => cached || fetch(request).catch(() => caches.match("/offline.html")),
),
);
});
Specifications
- Language
- JavaScript
- Strategy
- cache-first + offline fallback
- Events
- install, activate, fetch
What is a .js file?
JavaScript (.js) is a plain-text source file for the JavaScript language — the scripting language of the web, also used server-side via Node.js. It is dynamically typed and event-driven, with first-class functions, prototypes, and (in modern syntax) modules, classes, and async/await.
How to use this file
Use an example .js file to test syntax highlighters, linters (ESLint), formatters (Prettier), bundlers, and JavaScript parsers, or as editor and diff-viewer fixtures.
Related files
- txtads.txtAn IAB ads.txt listing authorised digital sellers with account IDs and relationships (sample data) — for testing ads.txt parsers and ad-fraud tooling.

- txthumans.txtA humans.txt crediting the people and stack behind a site, in the conventional TEAM/SITE block format — for testing plain-text metadata parsers.

- txtrobots.txtA robots.txt with wildcard and per-agent rules, a crawl-delay, and a sitemap reference — for testing robots parsers and crawler policy handling.

- txtsecurity.txt (RFC 9116)An RFC 9116 security.txt with Contact, Expires, Encryption, and Policy fields — normally served at /.well-known/security.txt, for testing security.txt parsers.

- xmlsitemap.xmlAn XML sitemap (sitemaps.org 0.9) with loc, lastmod, changefreq, and priority for several URLs — for testing sitemap parsers and crawl-scheduling tools.

- cC — Hello WorldThe classic hello-world in C — an include, main, and printf — for testing highlighters, C compilers, and parsers against the canonical first program.

Generated by generation/web_assets.py. Free for any use, no attribution required — license.