Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Last active December 19, 2015 10:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentcdodds/5941149 to your computer and use it in GitHub Desktop.
Save kentcdodds/5941149 to your computer and use it in GitHub Desktop.
How to check whether an external resource loaded and load a local copy if it failed to load. See README.md

Double Take Script Loader

This has been moved to an official Git repository

@klamping
Copy link

I think the code looks really clean. As a suggestion, I'd consider allowing a timeout method to be added, to give the CDN just a little bit of time to load the script before bailing out to the local copy. Also, I assume that removing the script stops the CDN version from loading? Good stuff.

@kentcdodds
Copy link
Author

@klamping, thanks for the feedback. I'll look into the timeout concept a little. But I believe that the browser waits for each script to load/fail before moving on to parsing the rest of the document (hence the "best practice" of including scripts at the bottom of your page right before the tag).

@kentcdodds
Copy link
Author

Note to self Figure out a way to add an option for libraries that attach themselves to the namespace of other global variables (like jQuery plugins or AngularJS modules).

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