Guy Incognito
Guy Incognito

Reputation: 500

CDN fallback for fontawesome CSS

Does anyone have a solution for falling back to a local copy of fontawesome if the CDN is blocked or unavailable?

For bootstrap css I do the following:

if ($('body').css('color') !== 'rgb(51, 51, 51)') {
    $('<link rel="stylesheet" type="text/css" href="/css/bootstrap/3.2.0/bootstrap.min.css">').prependTo('head');
}

However I don't see how I can do this with fontawesome as I can't see what I would test?

I guess I can do an ajax request and detect a 404 - but would this mean the css is transfered twice on every request?

Upvotes: 0

Views: 936

Answers (1)

Reflic
Reflic

Reputation: 1421

If you want to check it the same way as bootstrap, you could check if any element with the class .fa has the property font-family: FontAwesome; This property is set by the fontawsome.css which is loaded by the CDN.

Upvotes: 5

Related Questions