{"id":17321764,"url":"https://github.com/avoidwork/tiny-serviceworker","last_synced_at":"2025-08-17T21:07:35.337Z","repository":{"id":50093915,"uuid":"224738612","full_name":"avoidwork/tiny-serviceworker","owner":"avoidwork","description":"Service Worker with automatic cache management for your PWA.","archived":false,"fork":false,"pushed_at":"2021-10-08T02:34:01.000Z","size":397,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-14T06:45:15.360Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avoidwork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["avoidwork"]}},"created_at":"2019-11-28T22:26:17.000Z","updated_at":"2023-12-03T07:52:29.000Z","dependencies_parsed_at":"2022-09-23T11:41:43.265Z","dependency_job_id":null,"html_url":"https://github.com/avoidwork/tiny-serviceworker","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-serviceworker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-serviceworker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-serviceworker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avoidwork%2Ftiny-serviceworker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avoidwork","download_url":"https://codeload.github.com/avoidwork/tiny-serviceworker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219851590,"owners_count":16556236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T13:39:29.955Z","updated_at":"2024-10-15T13:39:30.711Z","avatar_url":"https://github.com/avoidwork.png","language":"JavaScript","funding_links":["https://github.com/sponsors/avoidwork"],"categories":[],"sub_categories":[],"readme":"# tiny-serviceworker\nService Worker with automatic cache management for your PWA.\n\n## How do I use this?\n- Install from `npm` or clone from `github`.\n- Copy `sw.js` to root directory of web app.\n- Edit `sw.js`, renaming `name` \u0026 setting `urls` to the required files to run web app offline.\n- Increment the `version` integer any time a core asset changes to delete a stale cache.\n- Install `sw.js` in web app (see `loader.js`).\n\n```javascript\n(function () {\n\tfunction log (arg) {\n\t\tconsole.type(`[my-app:${new Date().getTime()}] ${arg}`);\n\t}\n\n\tif (\"serviceWorker\" in navigator) {\n\t\twindow.addEventListener(\"load\", async () =\u003e {\n\t\t\ttry {\n\t\t\t\tconst registration = await navigator.serviceWorker.register(\"/sw.js\", {scope: \"/\"});\n\n\t\t\t\tlog(`type=serviceWorker, message=\"ServiceWorker registration successful with scope: ${registration.scope}\"`);\n\t\t\t} catch (err) {\n\t\t\t\tlog(`type=error, source=serviceWorker, message=\"ServiceWorker registration failed: ${err.message}\"`);\n\t\t\t}\n\t\t});\n\t}\n}());\n```\n\n## Command Line Interface\nInstall with `npm` \u0026 use the cli to generate a service worker in the current directory.\n\n```\n$ npm i tiny-serviceworker -g\n$ sw --name=\"myapp\" --directories=\"assets/css,assets/js,assets/img\" --loader=true\n```\n\n#### Parameters\n#### name\nName of your PWA\n\n#### announce (optional - default true)\nBoolean to enable a `client.postMessage(\"version_$version\");`\n\n#### directories (optional)\nQuoted comma delimited relative (from root) directory names to include in generated service worker\n\n#### files (optional)\nQuoted comma delimited relative (from root) files to include in generated service worker\n\n#### increment (optional - default true)\nBoolean to auto-increment `version` integer in `sw.js`\n\n#### ignore (optional)\nQuoted comma delimited relative (from root) directories or files to exclude; supports * for wildcards\n\n#### hosts (optional)\nQuoted comma delimited hostnames valid for caching requests\n\n#### loader (optional - default false)\nBoolean to generate `loader.js` script for `sw.js`\n\n#### reload (optional - default false)\nBoolean to force clients to reload when cache has gone stale\n\n#### safari (optional - default true)\nBoolean to load service worker in Safari browser (based on `navigator.userAgent`)\n\n#### timeout (optional - default 1800)\nDefault cache TTL (seconds) on requested URLs. Does not apply to core assets!\n\n#### version (optional - default 1)\nCache version. Increment when core assets change.\n\n#### walk (optional - default true, requires 'directories')\nBoolean to enable/disable walking directories for cache inclusion\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-serviceworker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favoidwork%2Ftiny-serviceworker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favoidwork%2Ftiny-serviceworker/lists"}