Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cdnify

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cdnify

CLI tool and library to use CDN in production

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-38.89%
Maintainers
1
Weekly downloads
 
Created
Source

cdnify

Simple library to easily switch between local and CDN libraries.

Installation

Just run

$ npm install -g cdnify

Usage

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">
<head>
  <meta charset="UTF-8">
  <title>Foobar</title>
  <script src="js/foo.js" cdn="//mycdn.com/bar.js"></script>
  <link href="css/foo.css" cdn="//mycdn.com/bar.css">
</head>
<body>

</body>
</html>

By running

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

You will get

  <script src="//mycdn.com/bar.js"></script>
  <link href="//mycdn.com/bar.css">

in dist/index.html.

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

Options

  • --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.

Keywords

FAQs

Package last updated on 08 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc