AMP-Toolbox Cache URL
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
ampToolboxCacheUrl.createCacheUrl('cdn.ampproject.org', 'https://www.example.com').then((cacheUrl) => {
console.log(cacheUrl);
});
ampToolboxCacheUrl.createCurlsSubdomain('https://www.example.com').then((curlsSubdomain) => {
console.log(curlsSubdomain);
});