Node utility to inline images, CSS and JavaScript for a web page - useful for mobile sites
Go to file
Remy Sharp b7157fde66 Merge pull request #6 from chrisjaure/patch-1
Add support for ports other than 80
2011-05-15 12:46:18 -07:00
bin +x 2011-03-14 12:58:05 +00:00
lib Add support for ports other than 80 so it can work with things like servedir, for instance :) 2011-05-14 17:45:05 -07:00
.gitmodules npm packed up, and re-org of directory 2011-03-14 12:40:58 +00:00
package.json for some reason, pages with just a link wouldn't generate the CSS - so I fixed it :) 2011-03-14 12:55:37 +00:00
README.md Note about global install of inliner 2011-04-27 04:45:18 -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 servedir via npm. The latter will also install inliner into the system's bin path.

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

Alternatively, inliner can be run directly from the repository using Node:

$ node bin/inliner
$ ./bin/inliner

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

Limitations / Caveats

  • Whitespace compression might get a little heavy handed - all whitespace is collapsed from n spaces to one space.
  • Doesn't support @import rules in CSS
  • I've not tested it much (yet)! :)
  • It was written in about 2 hours or so, so the code is a little messy, sorry!