I have a custom font, stored as img/roboto/Roboto-Medium.ttf
. I initialize it in my CSS stylesheet using:
@font-face {
font-family: robotomedium;
src: url("img/roboto/Roboto-Medium.ttf");
}
There is currently only one div where the font is used, and it is in display: none;
until JQuery fades it in:
<div id="test" style="font-family: robotomedium; display: none;">Some text</div>
When needed, JQuery makes the div appear using:
$("#test").fadeIn();
Since the font is not present on the user's system, it needs to be downloaded from the server. I would think the client would download the font when the page loads, but it appears to wait until there is visible text. When the user sees the div appear, the font gets downloaded when it starts to be visible, and since that takes some time, the text is invisible for a second or so. How can I prevent this? I tried preloading the font, without much results.