Skip to content

Instantly share code, notes, and snippets.

@perifer

perifer/gist:3952349

Created Oct 25, 2012
Embed
What would you like to do?
Improved web font loader code to prevent FOUT
// Custom web font loader inspired by the TypeKit loader.
WebFontConfig = {
fontdeck: {
id: FONTDECK_ID
},
active: function() {
clearTimeout(this._timeout);
}
};
(function() {
var a = document.getElementsByTagName("html")[0];
a.className += " wf-loading";
WebFontConfig._timeout = setTimeout(function () {
a.className = a.className.replace(/(\s|^)wf-loading(\s|$)/g, ""), a.className += " wf-inactive"
}, 3000);
var wf = document.createElement('script');
wf.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment