@ampproject/toolbox-cache-url
    TypeScript icon, indicating that this package has built-in type declarations

    2.8.0 • Public • Published

    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);
      });

    Install

    npm i @ampproject/toolbox-cache-url

    DownloadsWeekly Downloads

    3,121

    Version

    2.8.0

    License

    Apache-2.0

    Unpacked Size

    82.5 kB

    Total Files

    6

    Last publish

    Collaborators

    • esth
    • ampprojectbot
    • kdwan
    • ampproject-admin
    • kristoferbaxter
    • jridgewell
    • choumx
    • amp-toolbox
    • fstanis
    • erwinmombay
    • samouri
    • caroqliu
    • rsimha
    • dvoytenko
    • patrickkettner
    • alanorozco