You can try two options.
First, the obvious, something to do with the image (img), change the src attribute, convert it to some other tag. But most likely it's not working, why you ask.
Second, the theoretically possible option. To do an ajax request to the desired picture and at the right time to call the abort method of the XMLHttpRequest object (for example, the jQuery function $.ajax returns a similar object). Thus, if we assume that the browser will cache the queries, the picture may be in the cache in case of successful execution. It should be checked.