I’ve got an application that computes holiday entitlement for shift workers using Javascript and APIs. However some of the APIs take a long long time to compute (Chrome thinks the browser has crashed). Does anyone know a way of allowing the scenes and views the render while continuing the record updates in the background? Or any other ways to speed up the API calls?
There’s a few options and others will have way more experience in actually implementing these and other ideas:
Look hard at your current API logic to cut down any unnecessary calling and looping through records where you can. A hidden table will provide lightening quick access to read-only data instead of retrieving data via the API for example. Step through your code to find out exactly what’s taking time.
Consider using async functions async function - JavaScript | MDN (mozilla.org) - pitfalls here include the potentially viewing old data not yet updated after calling a long function. So you might need to modify what they see - record flags, or blocking pages - until the update is complete.
Provide visual updates to the page during the updates using a progress bar or something else that demonstrates to the user something is happening. I’m inexperienced at this but I think browsers then are less likely to display alert messages if the current page HTML is changing (needs a reference and clarification?).
Thanks for the detailed response! It’s taking around 20 seconds which is long enough for the browser to come up with an “unresponsive” message.
The hidden table idea is great, I hadn’t thought of this. I’m doing a lot of GET requests so perhaps this could be useful.
Async functions feel a bit beyond my current skill set but from what you’ve written I’m guessing that it would, for example, allow a form to submit and while the code continues to run?
For the third suggestion, I have tried displaying an alert but it didn’t display until all the code had been finished anyway.
Sorry, I have another follow up question. What’s the best way to use the hidden tables?
I’ve got my knack-view-render.view_XXX pulling data in from the table onto variables I’ve initiated on the scene render. Then I use these variables on the form submit. Is there a better way to do this?