-
-
Save iainbeeston/b225fc3566e4adcc241a to your computer and use it in GitHub Desktop.
Example code for loading airbrake.js asynchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(s, id, cb) { | |
var js, fjs = document.getElementsByTagName(s)[0]; | |
if (document.getElementById(id)) return; | |
js = document.createElement(s); | |
js.id = id; js.type = 'text/javascript'; js.async = true; | |
js.onload = js.onreadystatechang = cb; | |
js.src = (("https:" == document.location.protocol) ? "https://ssljscdn" : "http://jscdn") + ".airbrake.io/notifier.min.js"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'airbrake-js-notifier', function () { | |
Airbrake.setKey('<your-api-key>'); | |
Airbrake.setHost('api.airbrake.io'); | |
Airbrake.setEnvironment('dev'); | |
Airbrake.setGuessFunctionName(true); | |
Airbrake.setErrorDefaults({ | |
url: document.URL, | |
component: "hello", | |
action: "world", | |
}); | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is asynchronous, but still blocks the onload event handler. The right way to load a script in a non-blocking fashion is described here: http://calendar.perfplanet.com/2012/the-non-blocking-script-loader-pattern/