Search code examples
javascriptpythoncssnetwork-programminguwsgi

Images (and css) randomly fails to load with no apparent reason


I have a simple Flask+SQLite app that lives on Digital Ocean droplet and is served by uWSGI (I'll add NGINX when I this issue is solved).

Every time that I load a page, some images fail to load the first time. It's totally random which images and when they fail to load. To overcome this issue, I've made a reloader function that detects the failed images and reload them until they're loaded. That produces network log like this one:

enter image description here

You can see that for example, icon_order_history.svg failed to load twice, and then successfully loaded the third time.

It's actually all fine if images don't load, I don't really mind it that much, but sometimes css fails to load and results in a situation like this one:

enter image description here

I don't know what could cause this, I don't think it's a bad internet connection since it also happens on localhost.

Here's the reloader function:

function imageRetry(e) {
    setTimeout(reloadImg, 1000, e);
}
function reloadImg(e) {
    var source = e.src;
    e.src = source;
}

Any help is welcome, also feel free to ask me any questions/request more info. TIA


Solution

  • After not being able to solve the issue for a couple of days. I've decided to redeploy everything using a slightly different method. That solved the issue but the reason behind slow/random load fails stays unknown.