Load jQuery from a CDN and have a fallback to own host

November 20th, 2012 by Alex Leave a reply »

Just sharing the idea of loading jQuery (or any other library) from CDN, with a fallback to own hosting:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
window.jQuery || document.write(unescape('%3Cscript type="text/javascript" src="/js/jquery-1.8.3.min.js"%3E%3C/script%3E'))

Also, you can drop the type attribute when you are developing with HTML5 doctype.

Comments are closed.