-
Notifications
You must be signed in to change notification settings - Fork 17
/
typekit-cache.js
59 lines (53 loc) · 1.12 KB
/
typekit-cache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(function(
// Constants
document,
style,
innerHTML,
getElementsByTagName,
// Config
storage,
key,
pattern,
delay,
// Vars
temp,
next,
i,
css
) {
// If CSS is in cache, append it to <head> in a <style> tag.
if (storage[key]) {
temp = document.createElement(style);
temp[innerHTML] = storage[key];
document[getElementsByTagName]("head")[0].appendChild(temp);
document.documentElement.className += " wf-cached";
}
// Find and cache the Typekit CSS.
(function cache() {
// Find matching CSS.
temp = document[getElementsByTagName](style);
next = "";
for (i = 0; i < temp.length; i++) {
css = temp[i][innerHTML];
if (css && css.match(pattern)) {
next += css;
}
}
// If there's matching CSS, cache it.
// Prefix cached CSS so it does not match the pattern.
if (next) storage[key] = "/**/" + next;
// Retry using exponential backoff.
setTimeout(cache, (delay += delay));
})();
})(
// Constants
document,
"style",
"innerHTML",
"getElementsByTagName",
// Config
localStorage,
"tk",
/^@font|^\.tk-/,
100
);