Answer the question
In order to leave comments, you need to log in
How to get an HTML stream in Gulp given a known URL?
The project uses critical CSS rules obtained using the Critical module. At the moment, it reads html from pre-saved web pages, the names of the routes, which then form part of the name of the generated critical css, are entered manually, which is very inconvenient if there are many routes (and therefore linked standard pages). And if the CSS changes, then you need to generate the critical one again, manually saving the pages again.
Therefore, there was a need for gulp to take a route from a pre-prepared object, download typical pages and generate CSS.
As it was before:
gulp.task("desktopCriticalCss", function() {
var critical = require('critical'),
object = "ProductProductCommon";
critical.generate({
base: 'uncss_ignore/',
src: object + '.html',
dest: 'css/critical/mobile' + object + '.css',
minify: true,
dimensions: [{
width: 1920,
height: 1080
}],
});
});
var url2filenames =
{
"ProductProduct":
[
"https://***.ru/samsung-sm-a300f-galaxy-a3-white-133955.html",
"https://***.ru/huawei-g620s-lte-black-136150.html"
],
};
module.exports.url2filenames = url2filenames;
var gulp = require("gulp"),
critical = require('critical').stream,
download = require("gulp-download-stream"),
request = require('request'),
url2filenames = require("./url_to_critical_filenames.js").url2filenames;
gulp.task("mobileCriticalCss", function() {
for (route in url2filenames) {
var urls = url2filenames[route];
urls.forEach(function(url){
request(url)
.pipe(critical({
dest: 'css/critical/mobile/mobile' + route + '.css',
minify: true,
dimensions: [{
width: 360,
height: 640
}]
}));
});
}
});
Answer the question
In order to leave comments, you need to log in
https://www.npmjs.com/package/request
var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question