How to Fallback to Different Stylesheet and JavaScript If CDN Fails

Including some CSS stylesheets and JavaScript static files such as Bootstrap and JQuery are very common in HTML pages. There are many reasons that causes CDN sites become unavailable or down. Consequently if your pages fail to download these files, certainly your pages fail to render properly. For some professional, enterprise or business critical websites it is almost a must to ensure these static files are downloaded without failure.

Below are some of the ways how to fallback CSS stylesheets and JavaScript static files to local or different CDN sources using only JavaScript.

Fallback CSS Style Sheets download

Here is example code snippets that fallbacks CSS stylesheets usually goes into HTML head.

Fallback JavaScript download

Here is example code snippets that to fallbacks JQuery and Bootstrap downloads. These code usually go into HTML head or at the end of HTML body.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.