I need around 150 fonts for my project. Loading all the fonts initially increases the page load time.
I tried googling but could not find an answer.
Scenario:
User will select a font option
from <select>
tag. and upon click, I have to retrieve the font dynamically and make sure the font is rendered by the browser and then use the font to avoid a Flash of Unstyled Text (FOUT)
Currently I am using AJAX
to request that font file
$.ajax({
type: 'GET',
url: "font-file-url",
async:false,
success: function(data) {
$("style").prepend("@font-face {\n" +
"\tfont-family: \""+fontValue+"\";\n" +
"\tsrc: local('☺'), url("font-file-url") format('opentype');\n" +
"}");
}
});
Problem
I dont know when exactly the font is being rendered by the browser, so I end up displaying FOUT