{"id":15018303,"url":"https://github.com/mohawk2/mojolicious-plugin-serviceworker","last_synced_at":"2026-03-27T02:32:15.025Z","repository":{"id":56832751,"uuid":"280977636","full_name":"mohawk2/Mojolicious-Plugin-ServiceWorker","owner":"mohawk2","description":"Mojolicious plugin to add a Service Worker","archived":false,"fork":false,"pushed_at":"2020-07-20T13:16:20.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T01:06:02.025Z","etag":null,"topics":["javascript-service-worker","mojolicious-plugin","perl"],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Mojolicious::Plugin::ServiceWorker","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohawk2.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-20T00:44:43.000Z","updated_at":"2020-07-20T13:15:56.000Z","dependencies_parsed_at":"2022-09-08T01:41:21.292Z","dependency_job_id":null,"html_url":"https://github.com/mohawk2/Mojolicious-Plugin-ServiceWorker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2FMojolicious-Plugin-ServiceWorker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2FMojolicious-Plugin-ServiceWorker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2FMojolicious-Plugin-ServiceWorker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2FMojolicious-Plugin-ServiceWorker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohawk2","download_url":"https://codeload.github.com/mohawk2/Mojolicious-Plugin-ServiceWorker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243318751,"owners_count":20272137,"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":["javascript-service-worker","mojolicious-plugin","perl"],"created_at":"2024-09-24T19:51:48.561Z","updated_at":"2025-12-28T08:37:37.544Z","avatar_url":"https://github.com/mohawk2.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAME\n\nMojolicious::Plugin::ServiceWorker - plugin to add a Service Worker\n\n# SYNOPSIS\n\n    # Mojolicious::Lite\n    plugin 'ServiceWorker' =\u003e {\n      route_sw =\u003e '/sw2.js',\n      precache_urls =\u003e [\n      ],\n    };\n    app-\u003eserviceworker-\u003eadd_event_listener(push =\u003e \u003c\u003c'EOF');\n    function(event) {\n      if (event.data) {\n        console.log('This push event has data: ', event.data.text());\n      } else {\n        console.log('This push event has no data.');\n      }\n    }\n    EOF\n\n# DESCRIPTION\n\n[Mojolicious::Plugin::ServiceWorker](https://metacpan.org/pod/Mojolicious::Plugin::ServiceWorker) is a [Mojolicious](https://metacpan.org/pod/Mojolicious) plugin.\n\n# METHODS\n\n[Mojolicious::Plugin::ServiceWorker](https://metacpan.org/pod/Mojolicious::Plugin::ServiceWorker) inherits all methods from\n[Mojolicious::Plugin](https://metacpan.org/pod/Mojolicious::Plugin) and implements the following new ones.\n\n## register\n\n    my $p = $plugin-\u003eregister(Mojolicious-\u003enew, \\%conf);\n\nRegister plugin in [Mojolicious](https://metacpan.org/pod/Mojolicious) application, returning the plugin\nobject. Takes a hash-ref as configuration, see [\"OPTIONS\"](#options) for keys.\n\n# OPTIONS\n\n## route\\_sw\n\nThe service worker route. Defaults to `/serviceworker.js`. Note that\nyou need this to be in your app's top level, since the service worker\ncan only affect URLs at or below its \"scope\".\n\n## debug\n\nIf a true value, `console.log` will be used to indicate various events\nincluding SW caching choices.\n\n## precache\\_urls\n\nAn array-ref of URLs that are relative to the SW's scope to load into\nthe SW's cache on installation. The SW URL will always be added to this.\n\n## network\\_only\n\nAn array-ref of URLs. Any fetched URL in this list will never be cached,\nand always fetched over the network.\n\n## cache\\_only\n\nAs above, except the matching URL will never be re-checked. Use only\nwhere you cache-bust by including a hash in the filename.\n\n## network\\_first\n\nAs above, except the matching URL will be fetched from the network\nevery time and used if possible. The cached value will only be used if\nthat fails.\n\n**Any URL not matching these three criteria** will be treated with a\n\"cache first\" strategy, also known as \"stale while revalidate\": the cached\nversion will immediately by returned to the web client for performance,\nbut also fetched over the network and re-cached for freshness.\n\n# HELPERS\n\n## serviceworker.route\n\n    my $route_name = $c-\u003eserviceworker-\u003eroute;\n\nThe configured [\"route\\_sw\"](#route_sw) route.\n\n## serviceworker.config\n\n    my $config = $c-\u003eserviceworker-\u003econfig;\n\nThe SW configuration (a hash-ref). Keys: `debug`, `precache_urls`,\n`network_only`, `cache_only`, `network_first`.\n\n## serviceworker.add\\_event\\_listener\n\n    my $config = $c-\u003eserviceworker-\u003eadd_event_listener(push =\u003e \u003c\u003c'EOF');\n    function(event) {\n      if (event.data) {\n        console.log('This push event has data: ', event.data.text());\n      } else {\n        console.log('This push event has no data.');\n      }\n    }\n    EOF\n\nAdd to the service worker an event listener. Arguments are the event\nname, and a JavaScript function expression that takes the correct args\nfor that event.\n\n## serviceworker.event\\_listeners\n\n    my $listeners = $c-\u003eserviceworker-\u003eevent_listeners;\n\nReturns a hash-ref mapping event name to array-ref of function\nexpressions as above. `install` and `fetch` are provided by default.\n\n# TEMPLATES\n\nVarious templates are available for including in the app's templates:\n\n## serviceworker-install.html.ep\n\nA snippet of JavaScript that will install the supplied service\nworker. Include it within a `script` element:\n\n    \u003cscript\u003e\n    %= include 'serviceworker-install'\n    \u003c/script\u003e\n\n# SEE ALSO\n\n[Mojolicious](https://metacpan.org/pod/Mojolicious), [Mojolicious::Guides](https://metacpan.org/pod/Mojolicious::Guides), [https://mojolicious.org](https://mojolicious.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohawk2%2Fmojolicious-plugin-serviceworker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohawk2%2Fmojolicious-plugin-serviceworker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohawk2%2Fmojolicious-plugin-serviceworker/lists"}