Blog

How good is the CDN you load your JavaScript libraries from?

5 min read
5 min read

Using third party libraries in your SharePoint Framework customizations allows you to build richer solutions faster. But there are some things to consider. Have you thought of them?

Third-party JavaScript libraries in SharePoint Framework

When building SharePoint customizations on the SharePoint Framework, you can reference third party libraries to build richer solutions quicker and more efficiently. Reusing existing functionality allows you to focus on the added value for your organization and lower the amount of code you have to maintain. But including these libraries in your solution will add up to its size, making it load slower for the end-users. A better alternative is for you to define these libraries as external resources.

Inconvenient SharePoint Framework external libraries

When referencing JavaScript libraries as external resources in the SharePoint Framework, how you reference them, depends on the format in which they are distributed. If they are a module you refer to them in one way, where they are a non-module, you have to reference them differently. The reference itself is pretty straight-forward, but how do you tell what the format is of the library you want to use?

Is this a JavaScript module or not?

Sure, you can try one format, see if it works, and use another if it doesn’t, but it’s hardly the case to call this approach productive.

Easily reference JavaScript libraries in your SharePoint Framework solution

A while ago, we released a free tool at Rencore, powered by SPCAF, that helps you determine the type of JavaScript library you want to use. All you have to do is paste the URL of the script and we will tell you exactly what kind of format it is, and also give you an exact code snippet to use in your project!

But there is yet another thing you should keep in mind when working with external libraries.

CDN is not a silver bullet

There are many resources on the Internet that recommend loading JavaScript libraries from CDNs. Using a CDN would theoretically help you deliver the static assets from your solutions to your users faster, speeding up loading the solution. But it’s not that simple.

CDNs are highly beneficial if your users work in multiple locations across the world. The distance between their computer and the server from which they download files matters, and the shorter it is, the faster they will download the files. But if your users work in the same office and rarely travel, you might not need a CDN at all. In fact, you could get even better performance from a server that your organization owns and configures optimally for delivering static assets.

Indeed, even if you could benefit from a CDN, not all of them serve static assets used in SharePoint Framework solutions equally well. The outcome is that many CDNs are used for different purposes and use average settings which, well, offer average results. So how do you know if you should use one CDN or another?

In the Rencore Script Check, we not only tell you how you should reference the particular JavaScript library, but also how well it is served from the URL you specified.

Rencore Script Check is an invaluable tool in your SharePoint Framework toolbox. Over the last few months, we got some great feedback from developers who use it every day when building SharePoint Framework solutions.

If you use Visual Studio Code, fellow SharePoint MVP, Elio Struyf has recently built an extension that allows you to use Rencore Script Check directly from VSCode

If you are in the browser, looking up the URL of your JavaScript library, go to renco.re/spfx-check and check its format and quality before using it in your project. If you want to check the quality of the libraries in your existing project, Elio’s extension is very convenient for that.

Build better SharePoint customizations with Rencore

SharePoint Framework offers you great capabilities for extending SharePoint beyond what’s possible out of the box. Like in any other SharePoint development model there are some considerations that you have to take into account to make the best use of it. At Rencore, we have combined over 40 years of experience developing on the SharePoint platform. And we put it all into solutions that you can use to build safe and well-performing customizations.

If you want to know more about how our solutions will help you build better SharePoint Framework customizations, head over to rencore.com/spfx and don’t hesitate to reach out if you have any questions.

Furthermore, you can check your SharePoint farm for violations against over 1000 rules regarding quality, security, performance, best practices, maintainability and supportability. Ensure your customizations are compliant with your organization and the industries policies with our software tool SPCAF.

LEARN MORE

Subscribe to our newsletter