I read a Hosk’s Top CRM Articles of the week  – 28th September – I would not have missed reading his compilation for a good deal. And found a link to the post on Dynamics CRM Performance Center: Understanding the Microsoft Dynamics CRM Performance Center, by Aiden Kaskela. I have tried to find the way to improve our form scripts performance.

How to Improve Form Scripts Performance?

Use the following practices to achieve the best perfomance:

First Impression

  • DON’T include the unnecessary JavaScript web resource libraries! More scripts in the form is time! However the scripts are cached in your browser after they are loaded the first time the user open in the browser, but the first “impression” is important.
  • DON’T include jQuery in your form scripts. What is the most important benefit of jQuery? Maybe is that it allows for easy cross browser manipulation of the DOM. Upps! This feature is explicitly unsupported within form scripts. Even if you decided to use the rest, the remaining capabilities of jQuery that are handy for programming Microsoft Dynamics CRM, consider on the following:

To avoid the performance issues, don’t load jQuery in the page (as I wrote in above).

$.ajax is used to perform request against the OData and SOAP endpoints. This is supported but there are alternatives: use the native XMLHttpRequest object directly and you don’t need to load jQuery.

Use the SDK:REST.js sample library. This is found in: Sample: Create, retrieve, update, and delete using the OData endpoint with JavaScript

  • DON’T load all scripts in the OnLoad event! Does your code only support OnChange events for the fields  or the OnSave? set the script library with the event handler for those events instead of the OnLoad event. This way loading those libraries can be deferred and increase performance when the form loads.

Collapsed Tab

  • COLLAPSE TABS to defer loading web resources: including web resources or IFRAMES in section inside collapsed tab avoids to be loaded. The resources will be loaded when the tab is expanded. The TabStateChange event occurs when the tab state changes.  Any code that is required to support web resources or IFRAMEs within collapsed tabs can use event handlers for the TabStateChange event and reduce code that might otherwise have to occur in the OnLoad event.

The following picture shows how to collapse tab:

Tab Properties
This picture shows how to write code for the TabStateChange event:

Tab Event

  • AVOID using scripts in the OnLoad event to hide form element. Instead, set default visibility options for form elements that might be hidden by default. Then use form script in the OnLoad event to show those elements you want to display.