A SharePoint Developer tutorial by Jayant Rimza
kalmstrom.com Lead Developer Jayant Rimza explains how to
ways to do that. The major methods are to register the file
on a page, to always load the file by using the SharePoint
CustomAction in Module and to load the file on demand by
using the Script on Demand function. This is valid for all
available for that page, and this normally works good.
The problem comes when you are modifying the SharePoint
ribbon using CustomAction and your CustomAction requires
available, to always load the files or to load them on demand.
files on every SharePoint page and most often you do not
need them all. You might only need them when a page is loaded
or custom actions are executed.
From SharePoint CustomAction in Module you can register
SharePoint site. Only use this method when you really need
to use the file all over SharePoint.
You can use this code to check condition and load other
in entire site:
You can directly write a block of
ScriptBlock="alert('script block loaded');"
file by a SharePoint function, and it will provide a callback
overall SharePoint performance.
There are three steps to load a script on demand: first
file, then register the file and finally execute the load
At the end of the file that is going to load dynamically
you need to add this line of code:
the key for that file. It does not have to be a file
name, I only used the filename to avoid confusion. This
key should be the same when you register the dynamic
loading file and execute the load function.
files, because internally SharePoint stores them in
associate array with this key and value as path.
This function is used to register the file for the Script
on Demand that you want to load later.
if (_spPageContextInfo.webServerRelativeUrl !==
thisUrl = _spPageContextInfo.webServerRelativeUrl;
SP.SOD.registerSod accepts two arguments, the key for
the file and its SharePoint path. This function registers
the file in the SharePoint memory so that it will be
file and execute the method.
This SharePoint function accepts three arguments: the
key, the name of the function and the callback function
that is executed after the file has been loaded. The
key should be the same that you used in the method,SP.SOD.registerSOD.
(You can pass null into the second argument, because
Note that the callback function,fn??? should not be
in the file that is going to load. Instead it should
file. After this callback function you can use all functions
- Do not always load all your files in SharePoint
using CustomAction. It will slow down SharePoint performance.
- You can load files when they are needed by SOD at
event, button click, page load etc.
that will notify SharePoint that the file is loaded
- Register the file using the function
- Use executeFunc to load the file when needed. This
method executes a callback function once the loading
is done by SharePoint:
SP.SOD.executeFunc(key, null, callback);
- In all three steps to load the files dynamically,