Created
December 11, 2015 14:27
-
-
Save atma/0fa1934094519710fa2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Woff font loader with localStorage caching | |
function loadFont(a, b, c, d) { function e() { if (!window.FontFace) return !1; var a = new FontFace("t", 'url("data:application/font-woff2,") format("woff2")', {}), b = a.load(); try { b.then(null, function () { }) } catch (c) { } return "loading" === a.status } var f = navigator.userAgent, g = !window.addEventListener || f.match(/(Android (2|3|4.0|4.1|4.2|4.3))|(Opera (Mini|Mobi))/) && !f.match(/Chrome/); if (!g) { var h = {}; try { h = localStorage || {} } catch (i) { } var j = "x-font-" + a, k = j + "url", l = j + "css", m = h[k], n = h[l], o = document.createElement("style"); if (o.rel = "stylesheet", document.head.appendChild(o), !n || m !== b && m !== c) { var p = c && e() ? c : b, q = new XMLHttpRequest; q.open("GET", p), q.onload = function () { q.status >= 200 && q.status < 400 && (h[k] = p, h[l] = q.responseText, d || (o.textContent = q.responseText)) }, q.send() } else o.textContent = n } }; | |
//loadFont('Lato400', '/assets/fonts/lato/lato.woff.css', '/assets/fonts/lato/lato.woff2.css'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has bug for safari private:
fix with:
try { h = localStorage;h[42]=42; delete h[42]; || {} }