I want to use CSOM but waiting around 2 or 3 seconds after page load before I can even do my first query is crazy! See below. Using jQuery dom ready shows a reasonable ready time, but SP.ClientContext
isn't defined yet. Using ExecuteOrDelayUntilScriptLoaded
makes sure SP.ClientContext
will be defined, but it takes too long. In Chrome it can be around 1 second or not fire at all, in IE it's 500ms, still not really good enough. Is there ANYTHING I can do to speed this up??
Generally I want to perform Ajax requests before dom is ready, then in the Ajax callback, place a dom ready listener if I want to modify the dom.
//console.time implementation for IE
if(window.console&&typeof window.console.time=="undefined"){console.time=function(e,t){if(!e){return}var n=(new Date).getTime();if(!console.timeCounters){console.timeCounters={}}var r="KEY"+e.toString();if(!t&&console.timeCounters[r]){return}console.timeCounters[r]=n};console.timeEnd=function(e){var t=(new Date).getTime();if(!console.timeCounters){return}var n="KEY"+e.toString();var r=console.timeCounters[n];if(r){var i=t-r;var s=e+": "+i+"ms";console.info(s);delete console.timeCounters[n]}return i}}
console.time("SP");
ExecuteOrDelayUntilScriptLoaded(function(){
console.timeEnd("SP");
console.log(SP.ClientContext);
}, "sp.js");
console.time("jQuery");
$(function() {
console.timeEnd("jQuery");
console.log(SP.ClientContext);
});
Output:
jQuery: 67ms
undefined
SP: 2106ms
function()