4 ms·
What’s the current thinking on stashing fonts in localStorage for FOUT reduction?
by inopinatus 7y ago
What’s the current thinking on stashing fonts in localStorage for FOUT reduction?
- microcolonel 7y agoProbably better to split your font, and put your critical glyphs somewhere fast. Plus localStorage limits are very low, a couple decent sized fonts will blow your budget.
- EGreg 7y agoIs IndexedDB bigger? Why not use that?
- bhl 7y agoYou can. Another thing you can do is setup a service worker and intercept requests to Google Fonts, responding with an entry from cache or indexeddb instead.
- deleted 7y ago[deleted]
- EGreg 7y agoThat service worker stuff doesn’t work in iOS Safari though Can service workers intercept requests to other sites?
- ficklepickle 7y agoIt does since like 11.1. Yes, SW can cache all resources. This is how offline PWAs work.
- EGreg 7y agoTalkin about WebView
- pier25 7y agoWhat would be the advantage over loading the fonts from the browser cache?
- mkj 7y agoSeems rude to take up space in the browser that won't automatically expire.
- deleted 7y ago[deleted]
- kevingadd 7y agolocalStorage at least historically is painfully synchronous and in some cases it has to be fully loaded from disk before the page's JS can run. So if you're sure you're going to be using the font on every page I guess you can eat that load penalty, but then you have to deal with the size limit for localStorage (~2mb worst case, iirc), and also go to the trouble of doing string encode/decode to get the raw font bytes, then shove the font bytes into a blob and get a url for the bytes so you can finally load the font. At the end of that whole song and dance you've wasted a bunch of CPU and probably wall clock time being clever. Not sure it'd be faster than just hosting the files locally the regular way.