{"id":19644331,"url":"https://github.com/ampproject/cloudflare-amp-optimizer","last_synced_at":"2025-04-28T13:31:41.826Z","repository":{"id":43096880,"uuid":"352714351","full_name":"ampproject/cloudflare-amp-optimizer","owner":"ampproject","description":"Implementation of AMP Optimizer for Cloudflare Workers","archived":false,"fork":false,"pushed_at":"2024-12-08T22:32:16.000Z","size":45,"stargazers_count":23,"open_issues_count":8,"forks_count":5,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-04-05T09:05:16.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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":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}},"created_at":"2021-03-29T16:40:56.000Z","updated_at":"2025-02-11T04:40:02.000Z","dependencies_parsed_at":"2024-11-11T14:28:21.879Z","dependency_job_id":"c336cf94-df04-4ee5-9624-dba9e7b3eb13","html_url":"https://github.com/ampproject/cloudflare-amp-optimizer","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%2Fcloudflare-amp-optimizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcloudflare-amp-optimizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcloudflare-amp-optimizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ampproject%2Fcloudflare-amp-optimizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ampproject","download_url":"https://codeload.github.com/ampproject/cloudflare-amp-optimizer/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:49.480Z","updated_at":"2025-04-28T13:31:36.765Z","avatar_url":"https://github.com/ampproject.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloudflare AMP Optimizer\n\nThe Cloudflare AMP Optimizer is a Cloudflare Worker that will automatically optimize and cache any AMP pages \u0026 content from your origin so everyone can get the benefit of AMP optimized pages, not just users going through the AMP Cache.\n\nSee it in action at our [live demo](https://optimizer-demo.ampdev.workers.dev/the_scenic/templates/template_1_article.amp.html).\n\n## Usage\n\n1. Create your own Cloudflare Worker Repo using this as a template.\n\n```bash\nnpx @cloudflare/wrangler generate my-worker https://github.com/ampproject/cloudflare-amp-optimizer\n```\n\n2. Configure the routes in `wrangler.toml`.\n3. Make any changes to `config.json` if needed (explanations below).\n4. Publish!\n\n```bash\nnpm run prod # calls wrangler publish --env=prod\n```\n\n## Configuration\n\n### Usage as a reverse proxy\n\nIf your origin is not CF backed, then you can only use the optimizer in reverse proxy mode. You may configure it via the `proxy` option:\n\n```json\n{\n  \"proxy\": {\n    \"worker\": \"YOUR_WORKER_DOMAIN\",\n    \"origin\": \"YOUR_ORIGIN_DOMAIN\"\n  }\n}\n```\n\nAn example configuration is available in [@ampproject/amp-toolbox](https://github.com/ampproject/amp-toolbox/tree/main/packages/cloudflare-optimizer-scripts/demo)\n\n### Passing configuration options to AMP Optimizer\n\nUnder the hood, `cloudflare-amp-optimizer` utilizes the [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/main/packages/optimizer#options) library. If you'd like to pass through configuration options to the underlying library, you may do so by adding it to the `optimizer` key within `config.json`. For example, to increase the hero image count from 2 to 5:\n\n```json\n{\n  \"optimizer\": {\n    \"maxHeroImageCount\": 5\n  }\n}\n```\n\n### Enabling KV Cache\n\nCloudFlare Workers have access to a [fast, globally available cache](https://developers.cloudflare.com/workers/runtime-apis/kv). We highly recommend you enable this feature. In order to use it, add `enableKVCache: true` to `config.json`, as well as specify the _bindings_ within the `wrangler.toml` file. The binding must be named `KV`.\n\n```toml\nkv_namespaces = [\n  { binding = \"KV\", id = \"YOUR_ID\", preview_id=\"YOUR_PREVIEW_ID\"}\n]\n```\n\nTo see an example, check out the demo's [wrangler.toml](https://github.com/ampproject/amp-toolbox/blob/main/packages/cloudflare-optimizer-scripts/demo/wrangler.toml) file.\n\n### Enabling image optimization\n\nIf you are a Business or Enterprise customer of Cloudflare, you may enable [Cloudflare Image Optimizations](https://developers.cloudflare.com/images/url-format). Just add `enableCloudflareImageOptimization: true` to the `config.json` file and images will be automatically optimized for multiple screen sizes.\n\nNote: due to current limitations in `workers.dev`, this does not yet work in reverse proxy mode.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampproject%2Fcloudflare-amp-optimizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fampproject%2Fcloudflare-amp-optimizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fampproject%2Fcloudflare-amp-optimizer/lists"}