Created
November 26, 2022 19:27
-
-
Save pingram3541/9a0bc1fb5e8f68bf72aa067964f9398e to your computer and use it in GitHub Desktop.
Script on elementor init, elementor ready/all elements loaded and how much time it took until all elements loaded output in console
This file contains hidden or 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
/** | |
* perf monitoring | |
* use: | |
* const end = Date.now(); | |
* const elapsed = end - start; // elapsed time in milliseconds | |
********************/ | |
const start = Date.now(); | |
//do stuff when Elementor initializes | |
window.addEventListener('elementor/frontend/init', function() { | |
//init fires @ init, not ready, so let's check for ready | |
var countedElements = 0; | |
elementorFrontend.hooks.addAction('frontend/element_ready/global', function ($scope) { | |
var elementorElCount = document.querySelectorAll('.elementor-element').length; | |
countedElements++; | |
if (elementorElCount == countedElements) { | |
var event = new CustomEvent( 'elementor_fully_loaded' ); | |
document.dispatchEvent(event); | |
} | |
}); | |
//all done | |
}); | |
//do stuff after all Elementor elements loaded | |
document.addEventListener('elementor_fully_loaded', function(e){ | |
const end = Date.now(); | |
const elapsed = end - start; | |
console.log(`Elementor fully loaded in ${elapsed} milliseconds`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment