Including width and height in <img> results in 2 requests
Author: ohosseinmardiCreated Sep 17, 2020Updated Sep 22, 2026
Basic info:
- Node.js version: 14.9.0
- jsdom version: 16.4.0
- canvas version: 2.6.1
Minimal reproduction case
const jsdom = require("jsdom")
const { JSDOM } = jsdom
class CustomResourceLoader extends jsdom.ResourceLoader {
fetch(url, options) {
console.log('resourceloader.fetch is called')
return super.fetch(url, options);
}
}
function jsdomExample(event, context) {
const htmlImageUrl_wxh = `<img src="https://example.com" width="1" height="1"/>`;
const htmlImageUrl = `<img src="https://example.com"/>`;
const resourceloader = new CustomResourceLoader()
const dom = new JSDOM(htmlImageUrl_wxh, {
resources: resourceloader,
});
};
jsdomExample()When running jsdom with htmlImageUrl_wxh that contains width and height in the image tag you can see that fetch is called twice vs running jsdom with htmlImageUrl without width and height fetch is called once.
How does similar code behave in browsers?
Chrome will make a single request in both cases.
Wondering if someone can explain why including the width and height attributes on the img tag results in two requests being made to the endpoint.
Source: jsdom/jsdom