In How should I work with Bootstrap and JavaScript links? , how to serve the files media, either via CDN server or local server, it was answered that it is interesting to keep the two: initially loading the file from the CDN and, in case of failure, having a fallback on the local server, such as it is done with jQuery:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/js/jquery-1.10.2.min.js"><\/script>')</script>
With JavaScript files, creating this fallback is trivial, as you just need to check the existence of the object, such as window.jQuery || ...
, but with other files such as CSS and images, this is not so trivial.
So how can you define a fallback to import CSS files?
The idea would be to look something like this:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script>bootstrapLoaded || document.write('<link rel="stylesheet" href="assets/css/bootstrap/3.3.7/css/bootstrap.min.css">')</script>