Defer Bound Functions to Improve the User Experience
This guide addresses how to defer long running, bound and displayed functions with defer_load
. You can use this to improve the user experience of your app.
If you need to defer and orchestrate multiple, dependent tasks then check out the Defer Long Running Tasks Guide.
Motivation
When a user opens your app, the app is loaded as follows
the app file is executed
the app template is sent to the user and rendered
a web socket connection is opened to enable fast, bi-directional communication as your interact with the app.
Thus any long running code executed before the app is loaded will increase the the waiting time before your users see your apps template. If the waiting time is more than 2-5 seconds your users might get confused and even leave the application behind.
Here is an example of an app that takes +5 seconds to load.
Now lets learn how to defer long running tasks to after the application has loaded.
Defer all Tasks
Its easy defer the execution of all bound and displayed functions with pn.extension(..., defer_load=True)
.
Defer Specific Tasks
Its also easy to defer the execution of specific, bound and displayed functions with pn.panel(..., defer_load=True)
.