Skip to content

Commit

Permalink
added penthouse timeout option (#140)
Browse files Browse the repository at this point in the history
* added penthouse timeout option

* Removing .nvmrc for pull request

* column separators should be aligned with the others
  • Loading branch information
leogdion authored and addyosmani committed Jun 24, 2016
1 parent 6a2e129 commit d7e5947
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ critical.generate({
// Extract inlined styles from referenced stylesheets
extract: true,

// Complete Timeout for Operation
timeout: 30000,

// Prefix for asset directory
pathPrefix: '/MySubfolderDocrot',

Expand Down Expand Up @@ -219,6 +222,7 @@ critical.generate({
| inlineImages | `boolean` | `false` | Inline images
| assetPaths | `array` | `[]` | List of directories/urls where the inliner should start looking for assets
| maxImageFileSize | `integer` | `10240`| Sets a max file size (in bytes) for base64 inlined images
| timeout | `integer` | `30000`| Sets a maximum timeout for the operation
| pathPrefix | `string` | `/` | Path to prepend CSS assets with. You *must* make this path absolute if you are going to be using critical in multiple target files in disparate directory depths. (eg. targeting both `/index.html` and `/admin/index.html` would require this path to start with `/` or it wouldn't work.)
| include | `array` | `[]` | Force include css rules. See [`penthouse#usage`](https://github.com/pocketjoso/penthouse#usage-1).
| ignore | `array` | `[]` | Ignore css rules. See [`filter-css`](https://github.com/bezoerb/filter-css) for usage examples.
Expand Down
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var help = [
' --include RegExp, @type or selector to include',
' --maxFileSize Sets a max file size (in bytes) for base64 inlined images',
' --assetPaths Directories/Urls where the inliner should start looking for assets.',
' --timeout Sets the maximum timeout (in milliseconds) for the operation (defaults to 30000 ms).',
' ----------------------------------------------------------------------.',
' Deprecated - use "--inline" to retrieve the modified HTML',
' critical source.html --inline > dest.html',
Expand Down Expand Up @@ -81,6 +82,9 @@ cli.flags = _.reduce(cli.flags, function (res, val, key) {
case 'maxfilesize':
res.maxFileSize = val;
break;
case 'timeout':
res.timeout = val;
break;
case 'assetpaths':
case 'assetPaths':
if (_.isString(val)) {
Expand Down
1 change: 1 addition & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ function generate(opts) {
url: file.getPenthouseUrl(opts, server.port),
css: csspath,
forceInclude: opts.include || [],
timeout: opts.timeout,
maxEmbeddedBase64Length: opts.maxImageFileSize || 10240,
// viewport width
width: dimensions.width,
Expand Down
16 changes: 16 additions & 0 deletions test/02-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ describe('Module - generate', function () {
}, assertCritical(target, expected, done));
});

it('should throw an error on timeout', function (done) {
var target = '.include.css';

critical.generate({
base: 'fixtures/',
src: 'generate-default.html',
timeout: 1,
dest: target,
width: 1300,
height: 900
}, function (err) {
assert.instanceOf(err, Error);
done();
});
});

it('should generate critical-path CSS with query string in file name', function (done) {
var expected = read('expected/generate-default.css');
var target = '.critical.css';
Expand Down

0 comments on commit d7e5947

Please sign in to comment.