In my app, there is an initialise
function that I want to execute only when two conditions are met: first, the window has finished loading ($(window).load()
), and second, Typekit has loaded.
$(window).load(function() {
try {
Typekit.load({ active: initialise });
} catch (e) {}
});
Currently, this code waits for all resources, such as images, to finish loading before it starts loading the Typekit web fonts. After the fonts have loaded, then the initialisation process begins.
However, I need Typekit to load before the window finishes loading in an asynchronous manner. Therefore, the revised code should be:
$(window).load(initialise);
try {
Typekit.load({ active: initialise });
} catch (e) {}
Now, the Web fonts load asynchronously. The challenge now is ensuring that the initialise
function triggers only when both conditions have been met. Sometimes, the window loads before Typekit, and other times the opposite happens.
So, how can I ensure that initialise
is triggered once both criteria are fulfilled?