{"id":19644319,"url":"https://github.com/ampproject/amp-sw","last_synced_at":"2025-04-28T13:31:40.912Z","repository":{"id":38425453,"uuid":"167083081","full_name":"ampproject/amp-sw","owner":"ampproject","description":"A drop in service worker library to help your AMP pages gain network resiliency in 1 line","archived":false,"fork":false,"pushed_at":"2023-12-15T17:42:51.000Z","size":2228,"stargazers_count":70,"open_issues_count":37,"forks_count":29,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-25T02:46:43.380Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ampproject.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-22T23:24:12.000Z","updated_at":"2024-02-20T14:50:53.000Z","dependencies_parsed_at":"2024-11-11T14:28:14.674Z","dependency_job_id":"2d6cffdb-8c12-47a6-ab5b-25bc556312c9","html_url":"https://github.com/ampproject/amp-sw","commit_stats":{"total_commits":50,"total_committers":7,"mean_commits":7.142857142857143,"dds":0.36,"last_synced_commit":"f31a4938f826e1e8676762c73472c09c0de5eb07"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Famp-sw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Famp-sw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Famp-sw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Famp-sw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ampproject","download_url":"https://codeload.github.com/ampproject/amp-sw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251319757,"owners_count":21570451,"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-11-11T14:26:41.098Z","updated_at":"2025-04-28T13:31:35.885Z","avatar_url":"https://github.com/ampproject.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![build](https://travis-ci.org/ampproject/amp-sw.svg?branch=master)](https://travis-ci.org/ampproject/amp-sw.svg?branch=master)\n# AMP Service worker\nAMP service worker is a service worker library for your AMP documents.\n\n**Purpose:** Enhance network resiliency and optimize AMP asset reuse for AMP documents.\n\n**Core use cases:**  \n- Cache AMP scripts with a `stale-while-revalidate` strategy for a longer duration than the default http response headers indicate.\n- Cache valid visited AMP documents, and serve only in case of flaky network conditions.\n- Cache assets which are critical to a page with a given strategy.\n- Cache an offline page in order to show when a user navigates to a page which was previously not visited.\n- Prefetch outgoing links from an AMP page.\n\n\n## Usage\nTo take advantage of AMP service worker, you'll need to host a resource loaded into the browser. Start by following these steps:\n\n- Host a service worker file at the same directory level as your AMP web app/ AMP page.\n- Add `amp-install-serviceworker`(https://amp.dev/documentation/components/amp-install-serviceworker) to your AMP documents and point it your service worker file.\ne.g.\n```html\n\u003camp-install-serviceworker\n  src=\"https://www.your-domain.com/serviceworker.js\"\n  data-iframe-src=\"https://www.your-domain.com/install-serviceworker.html\"\n  layout=\"nodisplay\"\u003e\n\u003c/amp-install-serviceworker\u003e\n```\n- Add the following code to your service worker file to get the benefits of AMP service worker out of the box.\n```js\nimportScripts('https://cdn.ampproject.org/sw/amp-sw.js');\nAMP_SW.init();\n```\n- You can configure amp service worker to customize the behavior of the service worker to fit your needs. e.g. You can cache your static assets, control your document timeout limits or add an offline page. Read more in [modules](#modules) section.\n```js\nAMP_SW.init({\n  assetCachingOptions: [{\n    regexp: /\\.(png|jpg|woff2|woff|css|js)/,\n    cachingStrategy: 'CACHE_FIRST',\n  }],\n  offlinePageOptions: {\n    url: '/offline.html',\n    assets: [],\n  },\n});\n```\n\n\n## Modules\n\nThe AMP service worker is built up of the following modules:\n1. [AMP caching module](https://github.com/ampproject/amp-sw/tree/master/src/modules/amp-caching) is responsible for caching the AMP binaries released as a part \ndeployment cycle. It is a non-configurable module and has the defaults based on AMP's release cycle.\n2. [Document caching module](https://github.com/ampproject/amp-sw/tree/master/src/modules/document-caching) is the module which is responsible for caching the AMP documents. This module serves the page from cache(if available) is the network request fails or does not serve within a configurable time limit.\n3. [Asset caching module](https://github.com/ampproject/amp-sw/tree/master/src/modules/asset-caching) is a lazily loaded and optional, it can be used to cache the static assets like images/ fonts etc. You can give the reg-exp for matching assets and the caching strategy(CACHE_FIRST/NETWORK_FIRST/CACHE_ONLY) for the same.\n4. [Offline page module](https://github.com/ampproject/amp-sw/tree/master/src/modules/offline-page) can be used to introduce an offline page to your web app. AMP_SW only caches the documents which the user has already visited. If in the absence of the network the user tries to navigate to a page which is not available in the cache, this offline page is shown as a backup to let the user know what happened.\n5. [Link prefetch module](https://github.com/ampproject/amp-sw/tree/master/src/modules/link-prefetch) provides link prefetch capabilities to the browsers which do not support `link rel=prefetch`. You can use this to prefetch links and serve them from the service worker cache for the next time.\n\nWhile `amp-sw` is divided into smaller sub modules, the core funationality of this project relies on the [Workbox](https://github.com/GoogleChrome/workbox) project. The `amp-sw` modules also extend parts of the Workbox project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampproject%2Famp-sw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fampproject%2Famp-sw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampproject%2Famp-sw/lists"}