Not able to use v2 API with requirejs

detj

Posted on
Nov 17 2015

How can I load the rg4js object as mentioned in the documentation on this page [https://raygun.io/docs/languages/javascript]. The docs says the rg4js object is global. And I have two issues with that.

  1. Why is rg4js global?
  2. I looked at the source code here [https://raw.githubusercontent.com/MindscapeHQ/raygun4js/master/dist/raygun.js]. But didn't find the rg4js object anywhere in the JS source. Am I looking at an older version? The version in the file says v2.0.3 - 2015-10-30

It would be nice if the JS plugin is converted to UMD [https://github.com/umdjs/umd] which would make it easier to work with libraries like requirejs.

Any help would is highly appreciated.

Thanks


detj

Posted on
Nov 19 2015

Any thoughts on this?


Callum

Posted on
Nov 30 2015

Hi,

rg4js is global due to the lack of namespacing in JS and the browser. The global variable is necessary in order to provide an interface for async configuration at any point. Regarding your second point, the rg4js object is made available by the snippet as listed under Getting Started - Step 1 at https://raygun.io/docs/languages/javascript. This is to ensure configuring the provider can be accomplished by further code while Raygun4JS is potentially being downloaded by the browser. This is the same approach as many other similar libraries including Google Analytic's V2 snippet.

If there is a naming collision, rg4js can be renamed in the last line of the snippet to a different variable name, and that altered one be called to configure the provider.

Regarding module loading, that approach is useful for clientside namespacing and module graph referencing a la Node where scripts containing the various web application modules are download synchronously as all need to be present for execution. Requiring raygun4js 2.0 in this way would lead to the page being blocked while the assets are downloaded (minified or otherwise), and prevent the capture of early timing data for Pulse and page load errors for Crash Reporting. This concern is what lead to the development of the V2.0 release and the snippet which loads the library asynchronously.


Reply