node package manager



Simple library to easily switch between local and CDN libraries.


Just run

$ npm install -g cdnify


You just need to add the cdn attributes with the URL pointing to the CDN you want to get started.

For example, let say the following file is called index.html.

<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <script src="js/foo.js" cdn="//"></script> 
  <link href="css/foo.css" cdn="//">

By running

$ cdnify index.html -o dist/index.html

You will get

  <script src="//"></script> 
  <link href="//">

in dist/index.html.

If you want to keep the local source, pass the --use-local flag.


  • --output (aliased: -o): Set the output. Uses stdout if not set.
  • --use-local (default: false): Uses local file (set by src or href) instead of cdn
  • --incompatible (aliased: -i, default: []): Set a list of attributes incompatible with cdn. If used together, an error will return.
  • --cdn-attr (aliased: t, default: cdn): Set the attribute to be used for the CDN source.

Sample command:

$ cdnify -o foo.html --use-local -i glob -i other-attr --cdn-attr custom-attr

Public API

This module exposes two functions:

  • cdnify.process(rawHtml, options, callback) Arguments:

    • rawHtml: The raw HTML to process

    • options: The options as specified for the CLI. camelCase can be used instead of dash separated words.

    • callback: The callback to be called when done. The callback has the form:

      function (err, html, $) {

      where html is the processed HTML as a string and $ is an instance of cheerio, in case more processing is needed.

  • cdnify.processFile(filepath, options, callback) Excatly the same function as above, except that the first argument is the path to the HTML file to proces, instead of the raw HTML.