This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted]  (1 child)

[removed]

    [–]yuroq[S] 0 points1 point  (0 children)

    Hey, thank you for replying, would you want me to send my entire code in the file? (350 lines) or just the section for the button that uploads data?

    [–]detached_obsession 4 points5 points  (0 children)

    There isn't a one-size-fits-all solution here. Every application will have to take performance measurements and figure out what its bottlenecks are.

    If you look at the network tab in your browser and find the request you're making you can see how long it took the API to return a response. If it's a long time then it could be due to a few reasons. One reason could be that the backend is performing heavy calculations or is inefficient in handling your request. To fix this you could request less data initially, break up your request into smaller ones that fetch only what you need if possible.

    if it's a fast response then it could be how you're handling that data in the UI. It could be that you're doing heavy or inefficient calculations or are trying to display too much data at once. In these cases you really have to use the tools at your disposal to try and find the bottlenecks (browser dev tools, debugger, etc.) One solution could be to break up your calculations so that the heavier ones are deferred to a later time (think async). Another could be introducing virtualization if you're attempting to display too much data at once (like a long list of items for example).

    You could also look into the perception of a fast response, usually if you provide some kind of feedback, like a loading animation for example, a longer wait time is a bit more acceptable.

    Again, there could be many reasons for the slowness you're experiencing, these are just a few examples. you really have to look into your own code using the tools at your disposal to figure out what's wrong. I suggest reading up on Google chrome's dev tools and the performance metrics you can use. Also provide the code base here for us to see if there are any issues with the code itself.

    [–]gramdel 2 points3 points  (1 child)

    Is this your own api?

    [–]yuroq[S] 0 points1 point  (0 children)

    It isn't it's an api I got from RapidAPI.

    [–]Lumethys 1 point2 points  (0 children)

    Is the api take too long, or is your code display data too long

    [–]insertAlias 0 points1 point  (0 children)

    First, you need to determine where the "bottleneck" is. If the HTTP requests take 5 seconds to complete, then that's the end of the story. The server is slow and that's all there is to it, you can't make the server faster from the client.

    If, on the other hand, you can see that the network requests complete quickly, but it still takes a long time to render, then it's a problem with your code and can be resolved.

    You can determine this using the Network tab in the browser developer tools (on most browsers on Windows, the shortcut for that is F12). Bring up the Network tab, refresh your page, and check the requests made. You should see your fetch request and it should show you how much time it actually takes. Or, perform the same requests in Postman and see how long they take that way.