As I understand the situation, you want to load the first image with the page then after the page has loaded, replace the first image with an image from another source.
In the example below the default image is "https://via.placeholder.com/100", it is displayed as the page loads. The second image is "https://via.placeholder.com/300", and is displayed after page load is complete.
Set up all image tags by adding the attribute data-src="secondimage.jpg" in the image tag.
How this works: After page load is complete, the script loops over all img tags checking for the data-src attribute. If an img tag has a data-src attribute it replaces the src image with the address in data-src attribute.
If you want to pre-load the external secondary images just add new Image().src = "secondimage.jpg"; to your script.
If you press Run code snippet you will see the image shows 300 indicating the second image has replaced the first default one. See the commented section below for pre-loading secondary images if desired.
/*
uncomment if you want to pre-load the secondary images
new Image().src = 'https://via.placeholder.com/300';
new Image().src = 'https://via.placeholder.com/400';
new Image().src = 'https://via.placeholder.com/500';
... as many as necessary
*/
window.onload = function() {
imgs = document.querySelectorAll('img');
for (i = 0; i < imgs.length; i++) {
if (imgs[i].getAttribute('data-src')) {
imgs[i].setAttribute('src', imgs[i].getAttribute('data-src'));
}
}
}
<img data-src="https://via.placeholder.com/300" src="https://via.placeholder.com/100">