The Now Platform® Washington DC release is live. Watch now!
One of the most frustrating things you can encounter is a slow-loading page or form. Oftentimes when a page/form is loading slowly, it can be due to the server or client-side JavaScript. In this blog I will help you identify the source of the slowness and how to debug it.
One way to identify whether the slow page is due to client scripts or something on the server side is to look at the top of the page. While it is loading, if you see something like this that shows the running transaction time, that means it is the server that is taking its time:
If you see that page is loaded but the browser is still spinning, that means something on the client side is slow. Once the page is finished loading, you can always check the response time on the clock at the bottom right corner to see the server and browser times. If the source of the slow load is on the client side, Chrome dev tools can be used to pinpoint the slow JavaScript. Let's take a closer look at how to do this.
Let's take an example of an incident form. When I try to load incident form it takes ~2.5 seconds, out of which ~1.5 seconds is browser time and ~800 ms server time. This is not that bad, but let's see if we can optimize it further.
This is the response time that displays when I click on the clock icon at the bottom right corner:
Now let's open the Chrome developer tools on the incident form for more debugging.
There are two methods to opening Chrome dev tools:
Option 1: When you are on the form you want to debug, right-click the form and do inspect.
Option 2: In the Chrome menu, go to More Tools > Developer Tools. Depending on which version of Chrome you are on, it may be in a different location but usually clicking the wrench icon in the upper right will get you to this option.
var caller = g_form.getReference('caller_id');
if (caller.vip == 'true')
g_form.setValue('location', caller.location);
}
5. This looks like a client script to me, so I will search this client script in my instance. To look for the client script:
I am able to find the client script using the sys_id, its On Load client script (VIP Assignment Group) on the Incident table.
6. Let's check the script in the client script. Here is my code:
Looks like a bad code - we are doing a server call from the client script to set the assignment group. To avoid the server call add display value, I will rewrite the code as per Client Script Best Practices by jake.gillespie. Here is my updated code:
As we can see in my rewritten code above, there are three client scripts that were slow. I fixed all three of them using the same steps (1 through 6) and now my incident form is loading 1.2 seconds, out of which browser time is dropped down to 130 ms. Not bad.
In this example it was the client script that was causing slowness. Please note the client-side script is also coming from UI scripts or the script sections in UI Policies. Bottom line here is if you have a slow form load due to client-side scripting, take a moment to debug slowness using the browser performance tool.
Note: This example assumes that you are using the Chrome browser, but the other browsers have JavaScript consoles. I recommend you use Chrome when it comes to debugging and troubleshooting as it is pretty simple and easy to use. Also please note, I am on Chrome Version 58. If you are not on latest version of Chrome, use Timeline and Profile Panel as they are similar to the performance panel we just used.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.