@ampproject/toolbox-cache-url

中文文档
2.10.1发布于 2024/06/14Apache-2.0TypeScriptESM + CJS近 30 天下载 5040

Transform canonical URLs into AMP Cache URLs

原始使用文档
文档目录3 节
  1. Usage
  2. Including the Module
  3. Using the module

AMP-Toolbox Cache URL

npm version

Translates an URL from the origin to the AMP Cache URL format, according to the specification available in the AMP documentation. This includes the SHA256 fallback URLs used by the AMP Cache on invalid human-readable cache urls.

Usage

Install via:

$ npm install @ampproject/toolbox-cache-url

Including the Module

ES Module (Browser)

import {ampToolboxCacheUrl} from '@ampproject/toolbox-cache-url';

CommonJs (Node)

const ampToolboxCacheUrl = require('@ampproject/toolbox-cache-url');

UMD (Node, Browser)

In the browser, include the UMD module in an HTML <script> tag. If using node, replace window with global.

const {ampToolboxCacheUrl} = window.ToolboxCacheUrl;

Using the module

  // Get an AMP Cache URL from a cache domain, and a canonical URL
  ampToolboxCacheUrl.createCacheUrl('cdn.ampproject.org', 'https://www.example.com').then((cacheUrl) => {
    // This would log: 
    // 'https://www-example-com.cdn.ampproject.org/c/s/www.example.com/'
    console.log(cacheUrl);
  });

  // Transform a canonical URL to an AMP Cache subdomain
  ampToolboxCacheUrl.createCurlsSubdomain('https://www.example.com').then((curlsSubdomain) => {
    // This would log: 
    // 'www-example-com'
    console.log(curlsSubdomain);
  });

版本与发布记录

@ampproject/toolbox-cache-url 共发布 35 个版本,首次发布于 2019/06/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.10.1latest2024/06/142 年前
2.10.02024/06/142 年前
2.9.02022/06/244 年前
3.0.0-canary.2canary2022/01/124 年前
2.8.02021/05/315 年前
2.8.0-canary.62021/03/195 年前

其他发布通道:beta → 1.1.0-beta.0,alpha → 2.7.1-alpha.0,canary → 3.0.0-canary.2。

关于 @ampproject/toolbox-cache-url 的常见问题

@ampproject/toolbox-cache-url 是什么?

Transform canonical URLs into AMP Cache URLs

如何安装 @ampproject/toolbox-cache-url?

在项目目录运行 npm install @ampproject/toolbox-cache-url,或使用 pnpm add / yarn add / bun add。

@ampproject/toolbox-cache-url 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ampproject/toolbox-cache-url 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ampproject/toolbox-cache-url 可以商用吗?

@ampproject/toolbox-cache-url 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ampproject/toolbox-cache-url 的下载量有多少?

根据 npm 官方下载统计,@ampproject/toolbox-cache-url 在 2026/10/06 – 2026/11/04 这 30 天内被下载 5,040 次,日均约 168 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ampproject/toolbox-cache-url 还在维护吗?

最新版本 2.10.1 发布于 2024/06/14(2 年前);至今共发布 35 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/06/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。