node package manager

collapsify

Inlines all of the JavaScripts, stylesheets, images, fonts etc. of an HTML page.

Collapsify

Inlines all of the JavaScripts, stylesheets, images, fonts etc. of an HTML page.

npm install -g collapsify

An HTTP server is installed as collapsify-server, which collapses the URL passed to “/?url=”. This HTTP server is systemd-aware: when running as a systemd service, collapsify will listen on the socket passed. Otherwise, this server defaults to listening on port 8020, which can be changed via the “-p” flag.

Additional options can by found via the built in usage information, collapsify-server -h.

var collapsify = require('collapsify');
 
collapsify('http://www.cloudflare.com', {
  headers: {
    Accept-Language: 'en-US'
  },
  logger: console,
}).then(function(output) {
  console.log(output);
});

The “collapsify” function takes the URL to collapse, as well as an object of options, and returns a promise that resolves to a Buffer.

Of these, “logger” is required.

  • logger: An object that exposes a bunyan instance-like API.
  • headers: An object of headers, to be added to each HTTP request.
  • forbidden: A regex that matches blacklisted resources that should be avoided while navigating.