inliner/README.md

65 lines
2.8 KiB
Markdown
Raw Normal View History

2011-03-14 05:22:59 +03: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](https://github.com/mishoo/UglifyJS "mishoo/UglifyJS - GitHub"))
- Strips white from CSS
- Base64 encode images
- Puts everything back together as a single HTML file with a simplfied doctype
2011-03-14 15:57:35 +03:00
## Installation
Check out a working copy of the source code with [Git](http://git-scm.com), or install `inliner` via [npm](http://npmjs.org) (the recommended way). The latter will also install `inliner` into the system's `bin` path.
2011-03-14 15:57:35 +03:00
2011-05-30 03:58:31 +04:00
$ git clone https://github.com/remy/inliner.git
2011-04-27 15:45:18 +04:00
$ 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](https://github.com/tmpvar/jsdom "tmpvar/jsdom - GitHub") and [uglify-js](https://github.com/mishoo/UglifyJS "mishoo/UglifyJS - GitHub")).
2011-03-14 15:57:35 +03:00
2011-03-14 05:22:59 +03:00
## Usage
2011-03-14 16:09:21 +03:00
### 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
2011-03-14 16:16:23 +03:00
To use inline inside your script:
2011-03-14 16:15:53 +03:00
var inliner = require('inliner');
2011-03-14 05:22:59 +03:00
2011-03-14 16:09:21 +03:00
inliner('http://remysharp.com', function (html) {
// compressed and inlined HTML page
console.log(html);
});
2011-03-14 05:22:59 +03:00
2011-03-14 16:15:53 +03:00
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.
2011-03-14 05:22:59 +03:00
I plan to include a web service at some point, but obviously this won't be able to access localhost domains.
2011-03-16 14:02:57 +03:00
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](http://remysharp.com/2011/01/31/simple-offline-application/)).
2011-03-14 05:22:59 +03:00
2011-05-19 16:45:56 +04:00
## 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
2011-03-14 05:22:59 +03:00
## Limitations / Caveats
- Whitespace compression might get a little heavy handed - all whitespace is collapsed from n spaces to one space.
2011-05-19 16:45:56 +04:00
- Compresses whitespace inside of `<pre>` elements