What if I use js before DOM rendering?

for example, I want to change the src before the img tag is rendered. If I write the js at the end of the body, the image will be sent two different requests for two different images.
I want to change this address before src sends the request. How can I do this?

Jun.09,2022

you can write two img tags and use a variable to show and hide the two img,display:none or block


you can write

like this.
<img data-src="" />

then use js to change the value of src, so that the request will only be sent once

Menu