What is the risk of an error on an already loaded page?

Asked

Viewed 68 times

1

I have an application where large data in AJAX requests are made, this generates a certain delay to place the data on the page.

I need to render an image where your path is a array. In my understanding the browser tries to load the image once but the array has not yet been processed, generating an error in the console. The browser tries to find the image again and in that attempt it succeeds because the array has already been processed.

For a user it would not see any problem, but on the console I get an error from

Undefined

Based on this follows some doubts:

  • We must always eliminate mistakes no matter how visually everything is "right"?
  • The best way to resolve the situation would be with a Catch?
  • Is there any technique or tendency to make a late shipment?
  • 1

    you then need to load the images after the array, if there is such a dependency, this is the right one to do

  • 1

    "On my notice the browser tries to load the image once but the array has not been processed yet" - would be the case to fix so that it doesn’t happen this way, since you managed to diagnose the problem.

1 answer

5


We must always eliminate mistakes no matter how visually everything is "right"?

It’s not all right, it’s all working, it’s different things, so you have to do it right, because what’s wrong one day brings you trouble.

Fiat 147 caindo aos pedaços andando pelas ruas

The best way to resolve the situation would be with a Catch?

No, it’s the worst thing to do in almost every situation. When there’s a mistake you fix it instead of pretending it’s not there. Search here on the site on the subject. Exception is the most poorly used language feature in programming nowadays. Few exceptions should be handled in code. I can’t guarantee because I didn’t see this happening and the code you do this way, but it looks like a programming error and not a momentary environment glitch, do the code correctly and you won’t need it. Use the catch in the event of a failure beyond their control.

Is there any technique or tendency to make a late shipment?

Yes, you have it here on the site and other places and apparently you already know it’s called Lazy loading, there is no specific answer because the question is general.

  • Heh, great image to illustrate!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.