SPFx WebPart - SP.Runtime.js evaluation takes a long time
-
08-02-2021 - |
Question
I have an existing JSOM web-part which reference the SPO runtime:
,
"sp-runtime": {
"path": "https://abc/_layouts/15/SP.Runtime.js",
"globalName": "SP",
"globalDependencies": [
"microsoft-ajax"
]
},
"sharepoint": {
"path": "https://abc/_layouts/15/SP.js",
"globalName": "SP",
"globalDependencies": [
"sp-runtime"
]
},
"sharepoint-doc-mgmt": {
"path": "https://abc/_layouts/15/SP.DocumentManagement.js",
"globalName": "SP",
"globalDependencies": [
"sharepoint"
]
}
I then reference it:
require("sp-init");
require("microsoft-ajax");
require("sp-runtime");
require("sharepoint");
The part works as desired but initial load takes over a minute. After generating a performance report, I see that SP.Runtime.js script evaluation takes over a minute:
I am not sure how to reference the runtime so as to avoid the delay. Thanks.
Solution
You could try to load the libraries directly.
SPComponentLoader.loadScript('/_layouts/15/init.js', {
globalExportsName: '$_global_init'
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript('/_layouts/15/MicrosoftAjax.js', {
globalExportsName: 'Sys'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript('/_layouts/15/ScriptResx.ashx?name=sp.res&culture=en-us', {
globalExportsName: 'Sys'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript('/_layouts/15/SP.Runtime.js', {
globalExportsName: 'SP'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript('/_layouts/15/SP.js', {
globalExportsName: 'SP'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript('/_layouts/15/sp.init.js', {
globalExportsName: 'SP'
});
})
.then((): Promise<{}> => {
return SPComponentLoader.loadScript('/_layouts/15/1033/strings.js', {
globalExportsName: 'Strings'
});
})
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange