The problem:
I am using w3.css(if you enter now w3schools.com
site is down for maintenance) for styling my website.The problem
Why not use JS like this?
$.each(document.styleSheets)
iterates through the styleSheets of the document. Check out https://developer.mozilla.org/en-US/docs/Web/API/Document/styleSheets for more info.
Then we specifically check if http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css
is accessible. We use the ternary operator var rules = sheet.ruless ? sheet.rules : sheet.cssRules;
The ternary operator works similar to an if statement, rules becomes sheet.rules if sheet.rules evaluates to true. If it is false it will become sheet.cssRules.
Lastly we check if there's anything in rules
. If there isn't, we fallback to our local stylesheet solution and add it to the of the document.
Although you may run into issues when using a very slow to load CDN. Alternatively you could use the onerror
event