Node utility to inline images, CSS and JavaScript for a web page - useful for mobile sites
Go to file
2011-05-30 13:38:13 +01:00
bin not re-requested assets, and trying to make use of a cache, and better command line options 2011-05-30 13:38:13 +01:00
node-compress@39b5c39140 changed submodule location 2011-05-30 12:38:10 +01:00
.gitignore ignore file 2011-05-15 22:22:34 +01:00
.gitmodules changed submodule location 2011-05-30 12:38:10 +01:00
inliner.js not re-requested assets, and trying to make use of a cache, and better command line options 2011-05-30 13:38:13 +01:00
jquery.min.js including local jQuery to allow for offline inliner use 2011-05-19 13:45:36 +01:00
package.json support gzip compression. Closes #8 2011-05-30 01:31:16 +01:00
README.md Wrong url on git clone method 2011-05-29 16:58:31 -07:00

Inliner

Turns your web page to a single HTML file with everything inlined - perfect for appcache manifests on mobile devices that you want to reduce those http requests.

What it does

  • Get a list of all the assets required to drive the page: CSS, JavaScript, images and images used in CSS
  • Minify JavaScript (via uglify-js)
  • Strips white from CSS
  • Base64 encode images
  • Puts everything back together as a single HTML file with a simplfied doctype

Installation

Check out a working copy of the source code with Git, or install inliner via npm (the recommended way). The latter will also install inliner into the system's bin path.

$ git clone https://github.com/remy/inliner.git
$ npm install inliner -g

inliner uses a package.json to describe the dependancies, and if you install via a github clone, ensure you run npm install from the inliner directory to install the dependancies (or manually install jsdom and uglify-js).

Usage

via npm

If you installed via npm, then you can use inliner via the command line as per:

inliner http://remysharp.com

This will output the inlined markup. You can easily save this to a new file for testing:

inliner http://remysharp.com > remysharp.html

To use inline inside your script:

var inliner = require('inliner');

inliner('http://remysharp.com', function (html) {
  // compressed and inlined HTML page
  console.log(html);
});

Note that if you include the inliner script via a git submodule, it requires jsdom to be installed via npm install jsdom, otherwise you should be good to run.

I plan to include a web service at some point, but obviously this won't be able to access localhost domains.

Once you've inlined the crap out of the page, add the manifest="self.appcache" to the html tag and create an empty file called self.appcache (read more).

Support

  • Collapses all white space in HTML
  • Strips all HTML comments
  • Pulls JavaScript and CSS inline to HTML
  • Compresses JavaScript via uglify (if not compressed already)
  • Converts all images to based64 data urls, both inline images and CSS images
  • Imports all @import rules from CSS (recusively)
  • Applies media query rules (for print, tv, etc media types)
  • Leaves conditional comments in place
  • If JavaScript can't be imported (or is Google Analytics), source is not put inline

Limitations / Caveats

  • Whitespace compression might get a little heavy handed - all whitespace is collapsed from n spaces to one space.
  • Compresses whitespace inside of <pre> elements