Freitag, 11. Dezember 2015

JSLink: Load multiple JavaScript files (e.g. jQuery)

Problem:
You want to load multiple JavaScript files to use when rendering e.g. a field in SharePoint 2013. For example you use a library such as jQuery. In either case, you need all the scripts loaded before you can start rendering.

Solution:
It is possible to download multiple JavaScript files when loading the web part. Just separate them with the pipe character, i.e. |.
For example, to load ~sitecollection/_catalogs/masterpage/jQuery.js and ~sitecollection/_catalogs/masterpage/my-custom-field.js, set the JSLink property of your target to:
JSLink="~sitecollection/_catalogs/masterpage/jQuery.js|~sitecollection/_catalogs/masterpage/my-custom-field.js"
Do not worry about SharePoint re-downloading the same script repeatedly if you use it to render multiple elements, SharePoint will not download a script more than one time.