8.2 When to Load File Data

The HTML and JavaScript required to run your Web Application is automatically downloaded when you launch the Web Page, but what about the application data you need to show and have access to? When and how much data is passed to the client is entirely under your control.

It is recommended that if you have a small amount of records and/or static table data this should be loaded up front, when the page is launched, using an asynchronous request to the application server. This data can then be stored in a global data object on the client so it is immediately available when you need to display it on the UI.

For large files and transactional data, it may be worth retrieving, or refreshing, this data, or a subset of data, just before displaying to ensure details are up to date and no other users have updated the data in the interim.

Whenever you choose to retrieve data, it is important to understand the difference between an asynchronous request to the application server and a synchronous request. When a synchronous request to posted all processing on the client stops until a response is received from the application server. In contrast asynchronous request allows the user to continue to interact with the web application while processing of the request to the application server continues in the background. Making asynchronous requests on a timer can be a good way to refresh information without the frustration of pausing the processing in the web application.

So the bottom line, there is a trade-off in performance and wait times and you as the developer must make the appropriate decision for your application - upfront or on request, it is up to you.

Refer to  Asynchronous vs Synchronous Database Access.