web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Do CRM-form scripts really require require.js (or others)?

(2) ShareShare
ReportReport
Posted on by 424

Hello Experts,

I’m writing this post because of the MSDN article regarding new CRM form rendering engine and its effects on JavaScript development (https://msdn.microsoft.com/en-us/library/gg328261%28v=crm.8%29.aspx). We may find the following information there:

If you have code that depends on another library to be fully downloaded and initialized, the most straightforward approach is to combine both libraries within a single JavaScript web resource with your code below the library code. A more sophisticated approach is to use libraries such as head.js or require.js to control how the separate libraries are loaded.

Because of above mentioned information I have prepared some tests. I’ve created 2 JavaScript web resources. The first one, named Common.js was over 4 MB library. Second one – Account.js contained implementation of Account entity form event handlers (OnLoad & OnChanged) and was using Common.js library for some logic.

I’ve attached both libraries to Account form and started testing. Results of my actions are described below:

  1. Both libraries have been loaded in parallel as it is described in the article (of course - Account.js was loaded much faster then Common.js).
  2. CRM form does not present us its UI until both libraries was 100%-loaded (instead it shows us “loading business logic” information).
  3. The first event handled by custom code (form onLoad) took place when all the form-attached libraries had been loaded.

I have tested many different combinations (entities: Account, Contact, Quote, different network throttling’s, etc.) and I wasn’t able to make Account.js code running on CRM form without loading all the forms-related libraries (in my case – it was over 4MB Common.js).

Of course – form rendering legacy mode was disabled during my tests. I tested both CRM Online and on-premise 2016 SP1 organizations.

My question is – why do we really need require.js of single file implementation (as MS describes it above)? It looks like CRM UI rendering engine presents us CRM forms and runs forms event handlers only when all the form-related libraries are loaded.

Any specific scenarios? Entities? Components?

Kind regards.

*This post is locked for comments

I have the same question (0)
  • Piotr Gaszewski Profile Picture
    424 on at

    Any comments :) ?

  • Verified answer
    m-r-t Profile Picture
    on at

    Dear Piotr

    I have come to the exact same conclusions as you did. Upon inspecting the page load mechanism, I found that the OnLoad handler always fires way long after all the Libraries have loaded. Thus, all these library-dependency solutions you see floating around the web are not actually necessary (and I've seen professionals implement them the wrong way, too!). This is true as long as you only execute code from the OnLoad-handler. If your library script consists of more than just declarations, i.e. code that runs immediately upon evaluation of the script, then yes, you would need to take precautions if your script requires another script.

    If you think about it, it makes sense: If CRM fired an OnChanged-handler for a field, which in turn updated another field, what if that other field's OnChanged-handler is registered in a library that is not yet loaded? CRM could defer firing of the OnChanged-handler in these situations, but I seriously doubt they would go through all that trouble, as it would make the system a lot more complicated.

    In a way it's true that Microsoft does not explicitly confirm this behavior. However, the whole "your library X depends on library Y" story is missing an important point - in reality it comes down to "when does your code execute?". Unfortunately it seems as if the difference between declaring your code, and running your code, is poorly understood.

    Kind regards,

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans