Reputation: 103
For example the page is sending a 'link' http headers field that I don't want to load an async CSS from. How can I block it? Is it possible that I get those headers, remove the LINK field from it, and then page will load without this addition CSS (non-placed in page body)?
I have tried to modify the headers to no avail.
request('https://www.google.com', function(err, resp, data){
if (resp.statusCode == 200) {
console.log(resp.headers); // headers
}
else {console.log(err);}
});
Request is a node.js module. I need to modify headers before they are loaded by browser (passing modified headers by 'render' with combination of ejs template is not working).
Upvotes: 0
Views: 1354
Reputation: 16276
Update: The OP is talking about "Web Linking", the RFC5988 stuff on prefetch resource with HTTP response header, and want to block such prefetch behaviour.
In order to do that, a proxy can be made manually, block all unwanted data, and only return HTTP headers and content of interest. For example:
router.get('/proxy-to-google', function(req, res) {
request('https://www.google.com', function(err, resp, data) {
// get interested headers from resp object, and set it in res
res.set('Example-Header', 'XXX');
...
res.send(data);
});
});
There are 3 types of head/header in the world of web, and it seems you have confused with these concepts.
<header>
element in HTML. These are visible element exists in HTML page body, mostly used to wrap elements such as title, navigation bar etc.<head>
element in HTML. This is the meta element of HTML document. It is not visible in page, but rather responsible to mark important information of HTML document, such as CSS stylesheet links, JavaScript file URLs etc.In your case, you are trying to block the 3rd kind of "head" above, and you can make it using @Zuei Zukenberg's proposal. This <head>
element has nothing to do with HTTP headers.
Upvotes: 0
Reputation: 81
Yes, its possible to remove the css and js links (they are not headers) from the html response and just display the result using jsdom or cheerio.
Upvotes: 2