How to best load images from rate-limited host?


I have to load images from a host that rate limits requests to ~2 per second. When scrolling in a list with many images, all loaded from the same host, that causes problems of course. How do I best implement a rate limiter in my app that keeps track of the requests and limits and makes sure the requests only go out when it is ok for the API again?

I would probably show a spinner/loader in place of the images while the API doesn’t let me load them.

Are there any libraries that solve this problem? Any code or examples I can refer to?


Looks potentially useful.


Hmm, so you would advise me to not just include the images via <img src=...> but download them using http and then…

I currently think I could maybe build a my-img component that controls the setting of the URL in src by counting images were loaded etc. Does this sound doable?

On the other side, normal lazy loading of images (only load when in viewport) could probably bring me a lot closer to “yeah, seems to semi work…”.


As I said in your other thread about this, I really would do all I could to solve this on the backend, but if you’re insisting on implementing rate-limiting in the app, yes, you will have to take charge of all the network activity instead of leaving things up to the webview.

1 Like