Skip to content

Instantly share code, notes, and snippets.

@sang4lv
Created February 23, 2017 03:01
Show Gist options
  • Save sang4lv/82477e381b80cfa3e9f613577e75d6ae to your computer and use it in GitHub Desktop.
Save sang4lv/82477e381b80cfa3e9f613577e75d6ae to your computer and use it in GitHub Desktop.
Detect when all requests initiated by scripts have completed. Requires Performance API
(function(P) {
var timer = setInterval(function() {
var requestCount = P.getEntriesByType("resources").filter(res => res.initiatorType === "script" && res.responseEnd === 0).length;
if (requestCount === 0) {
// all requests are loaded
// begin next step here...
clearInterval(timer);
}
}, 16 * 4); // interval set to approx. 100ms
})(window.performance);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment