Created
February 23, 2017 03:01
-
-
Save sang4lv/82477e381b80cfa3e9f613577e75d6ae to your computer and use it in GitHub Desktop.
Detect when all requests initiated by scripts have completed. Requires Performance API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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