Socket
Socket
Sign inDemoInstall

critical

Package Overview
Dependencies
466
Maintainers
3
Versions
109
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.1 to 1.2.2

14

CHANGELOG.md
v1.2.2 / 2018-04-02
===================
* Improved handling of protocol-relative asset urls [#288]
* Adjust test files according to [#293]
* Improve error reporting [#258]
* Replace gutil by fancy-log [#297]
* Update README.md [#296]
v1.2.1 / 2018-03-26
===================
* Add license file
v1.2.0 / 2018-03-19

@@ -3,0 +17,0 @@ ===================

6

lib/core.js

@@ -69,3 +69,3 @@ 'use strict';

oust.raw(htmlfile.contents.toString(), 'preload')
]).filter(link => link.$el.attr('media') !== 'print').map(link => link.value);
]).filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value)).map(link => link.value);

@@ -75,2 +75,6 @@ stylesheets = uniq(stylesheets).map(file.resourcePath(htmlfile, opts));

if (stylesheets.length === 0) {
return Promise.reject(new Error('No usable stylesheets found in html source. Try to specify the stylesheets manually.'));
}
return Bluebird.map(stylesheets, file.assertLocal).then(stylesheets => {

@@ -77,0 +81,0 @@ htmlfile.stylesheets = stylesheets;

35

lib/file-helper.js

@@ -8,3 +8,3 @@ 'use strict';

const Bluebird = require('bluebird');
const request = require('request');
const got = require('got');
const debug = require('debug')('critical:file');

@@ -121,24 +121,21 @@ const mime = require('mime-types');

* @param {string} uri
* @param {boolean} secure
* @returns {Promise}
*/
function requestAsync(uri) {
return new Bluebird((resolve, reject) => {
// Handle protocol-relative urls
uri = url.resolve('http://te.st', uri);
request({url: uri, strictSSL: false}, (err, resp) => {
if (err) {
return reject(err);
}
if (resp.statusCode === 403 || resp.statusCode === 404) {
console.log('Ignoring', uri, '(' + resp.statusCode + ')');
resp.body = '';
return resolve(resp);
}
function requestAsync(uri, secure = true) {
let resourceUrl = uri;
// Consider protocol-relative urls
if (/^\/\//.test(uri)) {
resourceUrl = url.resolve(`http${secure ? 's' : ''}://te.st`, uri);
}
if (resp.statusCode >= 200 && resp.statusCode < 300) {
resolve(resp);
}
debug(`Fetching resource: ${resourceUrl}`);
return got(resourceUrl).catch(err => {
if (secure) {
debug(`${err.message} - trying again over http`);
return requestAsync(uri, false);
}
return reject(new Error('Wrong status code ' + resp.statusCode + ' for ' + uri));
});
debug(`${resourceUrl} failed: ${err.message}`);
return Promise.resolve(err);
});

@@ -145,0 +142,0 @@ }

{
"name": "critical",
"version": "1.2.1",
"version": "1.2.2",
"description": "Extract & Inline Critical-path CSS from HTML",

@@ -37,2 +37,3 @@ "author": "Addy Osmani",

"get-stdin": "^6.0.0",
"got": "^8.3.0",
"group-args": "^0.1.0",

@@ -52,3 +53,3 @@ "indent-string": "^3.2.0",

"request": "^2.83.0",
"slash": "^1.0.0",
"slash": "^2.0.0",
"tempy": "^0.2.1",

@@ -55,0 +56,0 @@ "through2": "^2.0.3",

@@ -196,3 +196,3 @@ # critical [![NPM version][npm-image]][npm-url] [![Linux Build Status][travis-image]][travis-url] [![Windows Build status][appveyor-image]][appveyor-url] [![dependencies Status][depstat-image]][depstat-url] [![devDependencies Status Status][devdepstat-image]][devdepstat-url]

This is a usefull option when you e.g. want to defer loading of webfonts or background images.
This is a useful option when you e.g. want to defer loading of webfonts or background images.

@@ -261,3 +261,3 @@ ```js

var gulp = require('gulp');
var gutil = require('gulp-util');
var log = require('fancy-log');
var critical = require('critical').stream;

@@ -269,3 +269,3 @@

.pipe(critical({base: 'dist/', inline: true, css: ['dist/styles/components.css','dist/styles/main.css']}))
.on('error', function(err) { gutil.log(gutil.colors.red(err.message)); })
.on('error', function(err) { log.error(err.message); })
.pipe(gulp.dest('dist'));

@@ -272,0 +272,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc