I like to display lazy loaded images in my web-app using loading="lazy". The problem I have is that the client needs to have a time limited token to request images from the server.
If an image scrolls onto the viewport, the client needs to request a token and with this token the client can request the image. For doing so, I need some kind of event or trigger to be fired before the lazy loaded image is requested by the browser.
I can not send the token with the first page hit or somewhere inbetween because I do not know how long the user is visiting other parts of the app before the images get visible. The time varies between some seconds and hours.
<img onload="doStuff()" /> gets fired after the image has been loaded. This is too late. I need something before the image is requested.
I'm not bounded to use images or loading="lazy" to resolve this issue. Any workaround is also welcome.