chalk = require('chalk'),
fork = require('child_process').fork,
fs = require('fs'),
- http = require('http'),
https = require('https'),
lzma = require('lzma'),
Minimize = require('minimize'),
function testWillPeavy(done) {
readText(filePath, function(data) {
- var options = url.parse('http://www.willpeavy.com/minifier/');
+ var options = url.parse('https://www.willpeavy.com/minifier/');
options.method = 'POST';
options.headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
- http.request(options, function(res) {
+ https.request(options, function(res) {
res.setEncoding('utf8');
var response = '';
res.on('data', function(chunk) {
function testHTMLCompressor(done) {
readText(filePath, function(data) {
- var options = url.parse('http://htmlcompressor.com/compress_ajax_v2.php');
+ var options = url.parse('https://htmlcompressor.com/compress_ajax_v2.php');
options.method = 'POST';
options.headers = {
'Accept-Encoding': 'gzip',
'Content-Type': 'application/x-www-form-urlencoded'
};
- http.request(options, function(res) {
+ var info = infos.compressor;
+
+ function failed() {
+ // Site refused to process content
+ if (info) {
+ info.size = 0;
+ info.gzSize = 0;
+ info.lzSize = 0;
+ info.brSize = 0;
+ info = null;
+ done();
+ }
+ }
+
+ https.request(options, function(res) {
if (res.headers['content-encoding'] === 'gzip') {
res = res.pipe(zlib.createGunzip());
}
catch (e) {
response = {};
}
- var info = infos.compressor;
- if (response.success) {
+ if (info && response.success) {
writeText(info.filePath, response.result, function() {
readSizes(info, done);
});
}
// Site refused to process content
else {
- info.size = 0;
- info.gzSize = 0;
- info.lzSize = 0;
- info.brSize = 0;
- done();
+ failed();
}
});
- }).end(querystring.stringify({
+ }).on('error', failed).end(querystring.stringify({
code_type: 'html',
html_level: 3,
html_strip_quotes: 1,
function get(site, callback) {
var options = url.parse(site);
- var protocol = options.protocol === 'https:' ? https : http;
- protocol.get(options, function(res) {
+ https.get(options, function(res) {
var status = res.statusCode;
if (status === 200) {
if (res.headers['content-encoding'] === 'gzip') {
{
- "Amazon": "http://www.amazon.co.uk/",
- "BBC": "http://www.bbc.co.uk/",
- "CNN": "http://www.cnn.com/",
- "Bootstrap CSS": "http://getbootstrap.com/css/",
- "Eloquent Javascript": "http://eloquentjavascript.net/1st_edition/print.html",
+ "Amazon": "https://www.amazon.co.uk/",
+ "BBC": "https://www.bbc.co.uk/",
+ "Bootstrap CSS": "https://getbootstrap.com/docs/3.3/css/",
+ "Eloquent Javascript": "https://eloquentjavascript.net/1st_edition/print.html",
"ES6 draft": "https://tc39.github.io/ecma262/",
- "ES6 table": "http://kangax.github.io/compat-table/es6/",
+ "ES6 table": "https://kangax.github.io/compat-table/es6/",
"Google": "https://www.google.com/",
"HTMLMinifier": "https://github.com/kangax/html-minifier",
- "NBC": "http://www.nbc.com/",
- "New York Times": "http://www.nytimes.com/",
- "Stack Overflow": "http://stackoverflow.com/",
+ "NBC": "https://www.nbc.com/",
+ "New York Times": "https://www.nytimes.com/",
+ "Stack Overflow": "https://stackoverflow.com/",
+ "Twitter": "https://twitter.com/",
"Wikipedia": "https://en.wikipedia.org/wiki/President_of_the_United_States"
}