I am changing src of all images to '' using mutation observer. But browser is making the request to that image URL. How to block image requests from the browser?
Below is the code.
const observer = new MutationObserver(mutations => {
mutations.forEach(({
addedNodes
}) => {
addedNodes.forEach(node => {
if( node.tagName == "IMG" ){
node.setAttribute("data-src",src);
node.removeAttribute('src');
}
});
});
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
<img src="[IMG]" />is going to trigger a request. You need to start with<img data-src="[IMG]" />and then introducesrcrather than vice versa.data-srcin html, as we don't have control over html code. We are creating a third party script to block some elements from loading.