SharePoint JavaScript Context Development Part 5 – JavaScript Framework Governance

This blog is part of the blog series SharePoint JavaScript Context Development

Parts 3&4 are linked. Please read in order.

Team SPDEV #1

What if I told you that you did not need to include jQuery in everything you did? What if I told you that SharePoint has all the same functionality and that you only need jQuery if you are using a framework that requires it? Well, it’s true. Unless you are using SPServices, AngularJS, Bootstrap and the like you do not need jQuery.

However, this goes two ways, how do you know that the code, which you are using in SharePoint JavaScript libraries, won’t be scrubbed. You are putting your support contract time in Microsoft’s hands. If they update a piece of code, your entire intranet could come crashing down on you.

Clear governance decisions

First we talk patch governance. If there is a new patch in SharePoint, it has to be tested against all customizations. Governance is imperative to running a SharePoint farm, and if you are in charge of this process and don’t do it, expect to be the one blamed when things do, and will go wrong.

We can also look at the impact of loading additional frameworks into SharePoint that are already covered with out of the box code. What are the additional page load times? Will the framework work with MDS? Will this slow our pages down and frustrate our users? The answer to this is no, it will not slow things down too much if you modify external libraries to work properly with SharePoint. However, this is the problem; you have to edit all external libraries in one form or another so that they do not conflict with out of the box code. Testing this patch process in itself is a mind-boggling job, testing the framework with the entirety of SharePoint. Historically, jQuery, and other external libraries have been used a lot with SharePoint, with minimal bugs. We know it sometimes conflicts with MDS, disabling it and that some pages use a $ symbol in the code so that we should use no conflict mode. However, what about future patches? Do we have in our governance plan to check jQuery at each patch? I would say not if we can help it and to use it sparingly where needed, and only where it is needed.

Maybe many people disagree with me here. However, this is the thing almost all JavaScript developers will tell you what I have stated in the above paragraph, even the creators of jQuery say the same thing. We have 2 sides of the coin, use out of the box methods and test their usages with every patch from Microsoft, or test our code and external libraries with every patch. Limiting external libraries to where required. If you look at it, the problem is the same on both sides of the coin we need to test our code with every patch. Both introduce risk from Microsoft and patching; this has happened before in more cases from external libraries than internal changes.

 SharePoint does contain bugs

Another point I need to talk about is the bugs in SharePoint code. We know they exist, we often work around them and write small patches in our code. The JavaScript framework inside SharePoint is no exception. I have read blog posts of people coming across these issues and patching them. If done correctly in JavaScript, however, these patches can be graceful and reduce the risk of code breakage to a near non-existent level.

 Example code to help with this process

So since this is a developer blog, I will give you a little bit of code which we JavaScript developers like to call a Monkey Patch or a Duck Punch.

What I am doing here is using a modern browser to expedite the checking of any patches made by Microsoft so that we can update our customizations. We can use the same method of checking either by running one-time piece of code we paste into the console that checks our code or by having it built into our custom code.

Conclusion and Further Reading

So we have seen that it is not always a good idea to include external frameworks. However, we have also seen that with proper governance in place patch management need not be a big thing.

If you need any more information on patching SharePoint I recommend you try out these blog posts:

Coming Next

So what’s next for the series? Well, I said we do not need jQuery, so the next blog post will be me proving this point and showing you EVERY method in jQuery with its out of the box SharePoint equivalent. I can tell you now already that most of the time the SharePoint versions are way cooler.

Stay tuned!

Merken

About the author

When I don't have my time buried in MSIL and C#, I am passionately writing JavaScript, learning the bleeding edge technologies, building my super awesome computer system, drawing, going to the gym, and spending time with my beautiful girlfriend and cat Momo.