loading FontAwesome locally if the CDN fails

dustin caruso
Jan 5, 2017 · 1 min read
Image for post
Image for post

Just this week I had a problem w/ two of my clients’ websites. It seems that Font Awesome wasn’t loading from the CDN that they supply after you fill out the form on their “Get Started” page (pictured above). The solution I slapped together (below) will only work if your site is using this JavaScript loader (1st line of code below, but your’s won’t have all zeros).

It basically looks for a value that would be in an object returned with the FontAwesome code. If that value doesn’t exist, then it will use the CSS file specified in the “document.write…” line of code (replace this with the location and name of your local FontAwesome file).

<script src="https://use.fontawesome.com/0000000000.js"></script>

if (!window.FontAwesomeCdnConfig.useUrl) {
document.write('<script src="/my-site/css/font-awesome.min.css"><\/script>');

Please, let me know in the comments if this little tip helped you at all.

Originally published at dustin caruso.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store