Skip to content

Instantly share code, notes, and snippets.

@twkm
Last active November 9, 2016 16:40
Show Gist options
  • Save twkm/b9b6040fbd05ea18976da2830ec50ff7 to your computer and use it in GitHub Desktop.
Save twkm/b9b6040fbd05ea18976da2830ec50ff7 to your computer and use it in GitHub Desktop.
Snippet to load jQuery via Google Hosted Libraries, fallback to local version.

Load jQuery via Google Hosted Libraries

Loading jQuery via a Google Hosted Libraries allows it to load quicker, as other sites who have included it from Google's Hosted Libraries will ensure that jQuery is already available in the cache of many of your visitors' computers.

The following snippet of code will attempt to load jQuery from Google Hosted Libraries and fall back to a local version if it did not load correctly for any reason. Ensure that you update the path to your local version of jQuery in the code below.

<!-- Load jQuery via Google CDN, fall back to local version if not loaded -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>window.jQuery || document.write(unescape('%3Cscript src="/path/to/js/jquery.min.js" type="text/javascript"%3E%3C/script%3E'));</script>

jQuery on Google Hosted Libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment