# Loading js libraries via register\_asset

**URL:** <https://meta.discourse.org/t/loading-js-libraries-via-register-asset/156003>\
**Category:** Development\
**Created:** [June 26, 2020, 9:12am UTC](https://meta.discourse.org/t/loading-js-libraries-via-register-asset/156003 "2020-06-26T09:12:39Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)\
**Post date:** [June 26, 2020, 9:12am UTC](https://meta.discourse.org/t/loading-js-libraries-via-register-asset/156003/1 "2020-06-26T09:12:39Z")

</div>

I noticed that the js files added using `register_asset` via plugins are passed as a string to `eval` function.

The problem with eval is, it doesn’t add the object to the global scope as discussed here. `https://stackoverflow.com/questions/4670805/javascript-eval-on-global-scope` which is essential for using a js library.

To be specific, I was trying to use `https://github.com/muaz-khan/RecordRTC/blob/master/RecordRTC.js` in a plugin but the functions aren’t accessible in the ember files.

The workaround for this is to process the file with webpack, using `libraryTarget` as `umd`.

Many of the libraries are processed this way which seems to work out of the box.

Now I’m not an expert on these things, but just wondering whether it makes sense for discourse to add the registered assets to the global scope.

Note: Apologies if some of this sounds silly. I didn’t expect to fiddle with webpack to get js libraries working with discourse which motivated me to post this writeup. 😉

---

_[View the full topic](https://meta.discourse.org/t/loading-js-libraries-via-register-asset/156003)._
