Skip to content

Keeps a site's Typekit in localStorage and injects it on page load, eliminating the Flash Of Invisible/Unstyled Text.

License

Notifications You must be signed in to change notification settings

spicywebau/typekit-cache

 
 

Repository files navigation

Typekit Cache

Revision 5

Keeps a site's Typekit in localStorage and injects it on page load. Eliminates the annoying Flash Of Invisible/Unstyled Text (FOUT) and provides better UX for slow or offline connections.

The same requests are sent as in loading a Typekit regularly, and the Typekit embed code is unaltered. However, using this script may still violate the Typekit Terms Of Use.

Usage

Copy the contents of typekit-cache.min.js right before your Typekit (advanced) embed code. That's it, your website should be caching your Typekit happily.

<script>
	!function(e,t,n,a,r,c,l,s,o){ /* ... */ }( /* ... */ );
</script>
<script>
	(function(d) {
		var config = {
			kitId: 'abcd1234',
			scriptTimeout: 3000
		},
		h=d.documentElement, // ...
	})(document);
</script>

Notes

The regular Typekit behavior is not modified at all. Exceptions visible in the console (e.g. if the storage is not available) can be safely ignored. However, you should use separate <script> tags to ensure the Typekit embed code is still run if an exception occurs.

In addition to the regular wf-* classes, the wf-cached class is added to the <html> tag on cache hit.

To use sessionStorage instead, just replace the localStorage reference.

Typekits may be quite large, and the performance impact of injecting them as inline stylesheets is not well tested.

Contributing

Make sure PRs contain an updated minified version. Run npm run prepublish to build it.

Contributors

Thanks!

About

Keeps a site's Typekit in localStorage and injects it on page load, eliminating the Flash Of Invisible/Unstyled Text.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%