Open qtiki opened 4 years ago
I'm open to giving this a shot again now that browser tech has moved forward a bit.
In the past I've avoided it because of just how complex font loading is. So complex that it would more than double the size of the library just to handle font edge cases.
I wonder if it makes sense to have a separate plugin that adds font support to resource loader, rather than building it in the lib here given how much code seems to be required.
All that being said it has been a while since I looked into this problem space and the state of browsers so I'll at least do some investigation and see where we are. Or if your up to it, PRs are always welcome!
edit: one other complexity is that we support back to ie9 currently, so adding font support would need to support back to that browser as well. Even if we use a modern api we still have to write the fallbacks.
I think all you need is a Strategy around FontFaceObserver: https://github.com/bramstein/fontfaceobserver It supports old browsers and also is very lightweight
PRs welcome.
+1 to this concept - the Venn diagram of resource-loader users who also need to load fonts is likely a circle. :-) Happy to help test if someone with a better understanding of the internals is willing to take a shot.
It would be nice if the resource-loader supported dynamic font loading "out of the box". Currently loading dynamic fonts requires the use of an external package like https://github.com/typekit/webfontloader.
Loading fonts could be implemented with the new CSS Font Loading API: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Font_Loading_API
I know the technology is still experimental but the compatibility chart is already pretty good and hopefully will get better with time (Edge at least should be pretty 1:1 with Chrome now that they're switching to Webkit).