MSCRM Development Tips &Trick #1 – Minify your Javascript
I am starting a series of blog post about tips and tricks on developing solution using Microsoft CRM. The first tips I would like to share is about Javascript form customization.
In production environment, for the best result, ensure that you ‘minified’ your custom Javascript. It might not seem to have big impact on small set of Javascript, but as it grows over time, so does the benefit. So far, I found Google Closure compiler is the best one out there. You can specify different level of optimization starting from removing whitespace only, simple optimization which involves renaming methods and variables, to the ‘Advanced’ optimization which does the simple optimization plus pruning of unused methods. You might want to be extra careful when doing the ‘Advanced’ optimization, especially if you have dependencies with 3rd party JS libraries like JQuery as it doesn’t pick up external JS resources (yet). Most of the time, the Simple optimization will suffice.
As a comparison, I have a 100kb Javascript in my account form. After applying the ‘Simple’ optimization using Google Closure tools, now the size of my JS become 35kb. Around 60-70% improvement. Might not sound a lot, but it’s a great investment.
If you decided to go down this path, I highly suggest that you keep a backup of the original un-minified Javascript in your Source Control (eg: SVN, TFS, etc). Essentially, every time you decided to make changes to the form Javascript, you will need to copy the original un-minified JS to the CRM form, make the changes, save it back to the Source Control, and minify it. Alternatively, if you don’t want to keep the original JS in Source Control, you can use free JS formatter / beautifier (eg: http://jsbeautifier.org/) to format your JS nice and clean. The downside of this approach is you might not get all of the original variable / method names.