npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cache-cdn

v1.0.1

Published

Download cdn libraries for local use (e.g. unit tests). Define your cdn libs in one place and write the references into your html.

Readme

cache-cdn

Build Status Coverage Status Codacy Badge

Download cdn libraries for local use (e.g. unit tests). Define your cdn libs in one place and write the references into your html.

Getting Started

  • This library requires node ^7.0.0

cache-cdn:

  • downloads cdn dependencies to a specified directory
  • writes cdn script/link tags into your html
  • keeps track of downloaded cdn libs to avoid re-fetching

Setup

First, create a cdn.json file in the root of your project. This file will contain a list of dependencies by type (typically js and css).

{
    "js": {
        "replaceString": "<!-- cdn-js-libs -->",
        "replaceTemplate": "<script src='@'></script>",
        "downloadDirectory": "cdn/js",
        "dependencies": [
            "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js",
            "https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"
        ]
    },
    "css": {
        "replaceString": "<!-- cdn-css-libs -->",
        "replaceTemplate": "<link href='@'>",
        "downloadDirectory": "cdn/css",
        "dependencies": [
            "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
        ]
    }
}

This file is configured to download the 3 listed dependencies into respective cdn/js and cdn/css directories in your project. It will also replace tokens (values of "replaceString") with script/link tags containing your dependencies.

Second, add the replaceString values to your index.html

<html>
<head>
    <!-- cdn-js-libs -->
    <!-- cdn-css-libs -->
</head>
<body> ... </body>
</html>

Third, import cache-cdn and call it with a source and destination.

const cacheCdn = require("../cache-cdn");

cacheCdn({
    sourceFile: "app/index.html",
    destinationFile: "dist/index.html"
});

This results in the cdn files being downloaded to the cdn/js and cdn/css libraries respectively. The dist/html file will look like this:

<html>
<head>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js'></script>
    <link href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css'>
</head>
<body> ... </body>
</html>

When you download the cdn libraries, a cdn-lock.json file is created to keep track of versions and make sure downloads are not attempted when they are not needed. Make sure to check in the lock file so that server builds will not redownload your cdn libraries on every run.

Available Options

sourceFile

Type: string Default Value: null

Source html file to inject cdn dependencies into. Must contain the replaceString matching that in cdn.json.

destinationFile

Type: string Default Value: null

Once cdn entries are injected, they are written to the destinationFile.

downloadLibs

Type: boolean Default Value: true

Flag for enabling/disabling the downloading of cdn dependencies.

configFile

Type: string Default Value: cdn.json

Allows an alternate location and/or name for cdn.json file.

Options for cdn.json File

replaceString

Type: string Example: "<!-- cdn-js-libs -->"

A string token which will be found in the sourceFile and replaced with an array of "replaceTemplate" values before being written to the destinationFile.

replaceTemplate

Type: string Example: "<script src='@'></script>"

The value of replaceTemplate will be used to generate each needed cdn tag in your html file. As "dependencies" are iterated over, the @ symbol is replaced with each dependency url.

downloadDirectory

Type: string Example: cdn/js

Source html file which contains a replaceString matching that in cdn.json.

dependencies

Type: array Example: ["https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"]

Array full of urls to cdn libraries. In the event that you end up with two files with the same name being downloaded into the same directory (e.g. cdn/js), you can replace one of the strings with an object that has url and filename properties. The url will be the same as before, but you choose the alternate filename you want to use. The following is an example:

    ...
        "dependencies": [
            {"url": "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js", "filename": "jquery2.min.js"},
            "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
        ]
    ...

Release History

1.0.0 - initial release

Acknowledgements

I want to give a special thanks to F1LT3R as this project was heavily inspired by grunt-cdn-switch and to dimmreaper who forked that repo to better serve my needs.