Today we had an issue where the sp.core.js file was not initialized after the post back of a application page. So the other SharePoint JavaScript files like sp.js, sp.runtime.js threw errors (As in the screenshot below). So, the functionalities didn’t work as expected.
Environment
The sp.core.js file was referenced in the master page and our custom JavaScript file (the file where our functionalities are implemented. We were opening a modal pop up implementing some logics) was referenced in the aspx page. Our client wanted us to work only in the custom JavaScript file and not in the master page or in application page.
Solution
We used registerSod function which is available in SharePoint Script On Demand (SP.SOD) framework in order to load build in SharePoint JavaScript libraries.
- /* SP.SOD.registerSod(key value (any unique string), path of the script file); --- */
- SP.SOD.registerSod('sp.core.js', '\\_layouts\\sp.core.js');
- /* executeFunc is used to execute the file mentioned above. using dummy function --- */
- SP.SOD.executeFunc('sp.core.js', false, function () { });
- SP.SOD.registerSod('sp.js', '\\_layouts\\sp.js');
- SP.SOD.executeFunc('sp.js', false, function () { });
- SP.SOD.registerSod('sp.ui.dialog.js', '\\_layouts\\sp.ui.dialog.js');
- SP.SOD.executeFunc('sp.ui.dialog.js', false, function () { });
Reference
http://www.vlieshout.net/sharepoint-2013-lazy-loading-javascript/
No comments:
Post a Comment