{"id":19644322,"url":"https://github.com/ampproject/cdn-worker","last_synced_at":"2025-04-28T13:31:41.182Z","repository":{"id":37912181,"uuid":"394774791","full_name":"ampproject/cdn-worker","owner":"ampproject","description":"CDN worker source code","archived":false,"fork":false,"pushed_at":"2025-04-26T03:04:49.000Z","size":1893,"stargazers_count":11,"open_issues_count":4,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-26T04:28:12.802Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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":null,"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,"zenodo":null}},"created_at":"2021-08-10T20:33:30.000Z","updated_at":"2025-03-31T18:48:26.000Z","dependencies_parsed_at":"2023-09-27T21:26:05.916Z","dependency_job_id":"d145c5b1-fd0b-45c7-8b71-c746fd852874","html_url":"https://github.com/ampproject/cdn-worker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcdn-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcdn-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcdn-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcdn-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ampproject","download_url":"https://codeload.github.com/ampproject/cdn-worker/tar.gz/refs/heads/main","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.926Z","updated_at":"2025-04-28T13:31:36.101Z","avatar_url":"https://github.com/ampproject.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AMP CDN Worker ⚡\n\nThis repository is the source code for the web worker that powers the [AMP](https://amp.dev/) project's CDN server. This web worker runs on [Cloudflare Workers](https://workers.cloudflare.com/).\n\nA detailed explanation of the inner workings of this server is available in its original [design document](https://docs.google.com/document/d/1QD0SBwgmZxrvJTpv68ytTI2oKxq4EOi-mkSCKm2JTPc/edit).\n\n## Other useful information\n\n-   The [AMP meta repository](https://github.com/ampproject/meta) has information _about_ the AMP open source project, including AMP's [governance](https://github.com/ampproject/meta/blob/main/GOVERNANCE.md).\n-   The [amphtml repository](https://github.com/ampproject/amphtml) contains the source code for the AMP runtime itself and its extensions.\n-   [AMP's code of conduct](https://github.com/ampproject/meta/blob/main/CODE_OF_CONDUCT.md) documents how all members, committers and volunteers in the community are required to act. AMP strives for a positive and growing project community that provides a safe environment for everyone.\n\n## Maintenance\n\nPre-requisite: install the Wrangler CLI tool (`npm install --global wrangler`) and login (`wrangler login`). Ensure you have access to **Lamentis@amp.dev's Account** with `wrangler whoami`.\n\n### Worker environments\n\nWe are using three (3) different environments (defined in [wrangler.toml](./wrangler.toml)):\n\n-   `development`: uses separate `RTV` and `CONFIG` KV namespaces from `staging` and `production`\n-   `staging`: uses the same `RTV` and `CONFIG` KV namespaces as `production`, but does not serve traffic on https://ampjs.org/\n-   `production`: serves traffic https://ampjs.org/\n\n### Development\n\nMake your changes and run `wrangler dev --env development` (or `staging`, if you really need live `RTV`/`CONFIG` namespaces).\n\nNote that `development`'s KV namespaces are not updated automatically, so you will need to [manually update](https://dash.cloudflare.com/78e1d5140b47fc9dab18dc8b25351b7a/workers/kv/namespaces) the `RTV` namespace with an active RTV number for (at the very least) the `stable` field.\n\n### Deployment\n\nDeploy in rolling stages, and verify that the changes are stable. Do not skip this. Deployment command is: `wrangler publish --env development` (or `staging` or `production`)\n\n#### Verifying Brotli compression for dynamic files\n\nFiles that get dynamically modified before serving (`/v0.[m]js` and `/v0/amp-geo-*.[m]js`) have special handling to maximize their Brotli compression level _after_ they are first requested by each edge node.\n\nWhen a dynamic file is first requested, it will be served with Cloudflare Worker's default Brotli compression level, then a background thread in the Worker (our code) will compress the file with the maximum compression level and store it in the edge node's cache, to be served to subsequent requests. This process takes \u003c1s.\n\nThere are three (3) ways to verify that such files have been compressed successfully after publishing code updates:\n\n1.  (easy, but unscientific) open the browser's DevTools, request a dynamic file in the `development` environment and look at the fetch size in the Network tab. Wait 3 seconds, force-refresh the page, and see if the fetched size decreased by more than 0.2kb (which could indicate just network overhead differences)\n2.  (still easy, slightly more scientific but relies on a server implementation detail that might change in the future) inspect the response headers in the DevTools' Network tab. If the response header contains a `content-encoding: br` _and_ has a `content-length` field, the file has been compressed by our code and cached succesfully. This is because currently Cloudflare default Brotli compression does not indicate the content length, but requests that have been pre-cached do\n3.  (hard, but most accurate) in Cloudflare worker dashboard go to `Workers \u003e cdn-worker-development \u003e Logs \u003e Begin log stream`, then request the dynamic file and look for these lines in the log:\n\n    -   `\u003e Plain response cached` and `\u003e Brotli response cached`, or\n    -   `Serving \u003cURL\u003e with dynamic key \u003cKEY\u003e from cache`\n\nStatic files are pre-compressed on the storage backend and do not require any verification.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampproject%2Fcdn-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fampproject%2Fcdn-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampproject%2Fcdn-worker/lists"}