# Adding external JS lib globally to all Plugins and Theme (Components)

**URL:** https://meta.discourse.org/t/adding-external-js-lib-globally-to-all-plugins-and-theme-components/144823
**Category:** Development
**Created:** [March 19, 2020, 12:49pm UTC](https://meta.discourse.org/t/adding-external-js-lib-globally-to-all-plugins-and-theme-components/144823 "2020-03-19T12:49:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![domr109](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/domr109/32/160246_2.png) [@domr109](https://meta.discourse.org/u/domr109)
#### Post date: [March 19, 2020, 12:49pm UTC](https://meta.discourse.org/t/adding-external-js-lib-globally-to-all-plugins-and-theme-components/144823/1 "2020-03-19T12:49:56Z")

</div>

**Situation**

We want to add this external [logging JS](https://github.com/pimterry/loglevel) lib to our Discourse Instance to improve the debugging workflow by using this lightweight logging wrapper that allows us for example setting up a logLevel via `log.setLevel('debug')`.

This external lib should be available throughout all our custom plugins, Theme and Theme Components we have installed on our App.

**Implementation**

• Would importing the JS via `register_asset` in various Plugins import the JS file multiple times?  
• Is there an alternative JS lib with similar functionality after [Ember deprecated its logging utility](https://deprecations.emberjs.com/v3.x/) in favor of `console.log`

We currently went down following road to implement it.

1. Install Plugin which imports external JS and make JS lib available via window object (`window.log = log’)  
• Import JS lib only once imported  
• Other plugins/Theme/Theme Components would depend on that Plugin and things like open source plugins would force users to install both plugins

Does this make sense or would you suggest a different approach?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [March 24, 2020, 4:33am UTC](https://meta.discourse.org/t/adding-external-js-lib-globally-to-all-plugins-and-theme-components/144823/2 "2020-03-24T04:33:02Z")

</div>

This feels very decoupled to me… why not make a standalone plugin or component that introduces this and then just make sure you always install it?

---

<div class="post-metadata">

### Author: ![domr109](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/domr109/32/160246_2.png) [@domr109](https://meta.discourse.org/u/domr109)
#### Post date: [April 1, 2020, 7:57am UTC](https://meta.discourse.org/t/adding-external-js-lib-globally-to-all-plugins-and-theme-components/144823/3 "2020-04-01T07:57:58Z")

</div>

> [@sam](#):
>
> why not make a standalone plugin or component that introduces this and then just make sure you always install it?

Yes, that was actually the solution I mentioned we are using currently. Having 1 plugin that imports the JS and other plugins using it will depend on this plugin to be installed.

Thanks for the reply!
