Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check promise success #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions critical-foft-preload-fallback-optional.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,24 @@
document.documentElement.className += " fonts-loaded-2";
return;
} else if( "fonts" in document ) {
document.fonts.load("1em LatoSubset").then(function () {
document.documentElement.className += " fonts-loaded-1";
document.fonts.load("1em LatoSubset").then(function(fres) {
if (fres[0].length) {
document.documentElement.className += " fonts-loaded-1";

Promise.all([
document.fonts.load("400 1em Lato"),
document.fonts.load("700 1em Lato"),
document.fonts.load("italic 1em Lato"),
document.fonts.load("italic 700 1em Lato")
]).then(function () {
document.documentElement.className += " fonts-loaded-2";
Promise.all([
document.fonts.load("400 1em Lato"),
document.fonts.load("700 1em Lato"),
document.fonts.load("italic 1em Lato"),
document.fonts.load("italic 700 1em Lato")
]).then(function(fmres) {
if (fmres.every(function(f) { return f.length; })) {
document.documentElement.className += " fonts-loaded-2";

// Optimization for Repeat Views
sessionStorage.fontsLoadedCriticalFoftPreloadFallback = true;
});
// Optimization for Repeat Views
sessionStorage.fontsLoadedCriticalFoftPreloadFallback = true;
}
});
}
});
} else {
// use fallback
Expand Down