Skip to content
Branch: master
Find file History
Latest commit 1ac4da6 Aug 7, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
examples use lerna.js to manage packages Oct 23, 2018
lib moved test and lint tasks to root Oct 25, 2018
spec use lerna.js to manage packages Oct 23, 2018
README.md Fix NPM badges Aug 6, 2019
index.js use lerna.js to manage packages Oct 23, 2018
package.json v1.0.1 Aug 6, 2019
rollup.config.js Made requested changes Oct 24, 2018

README.md

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 'amp-toolbox-cache-url';

CommonJs (Node)

const ampToolboxCacheUrl = require('amp-toolbox-cache-url').createCacheUrl;

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.AmpToolboxCacheUrl;

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);
  });
You can’t perform that action at this time.