# Difficulties in correctly adding external JavaScript

**URL:** https://meta.discourse.org/t/difficulties-in-correctly-adding-external-javascript/118099
**Category:** Support
**Created:** [May 18, 2019, 6:00pm UTC](https://meta.discourse.org/t/difficulties-in-correctly-adding-external-javascript/118099 "2019-05-18T18:00:26Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![StevenTammen](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@StevenTammen](https://meta.discourse.org/u/StevenTammen)
#### Post date: [November 5, 2019, 3:33am UTC](https://meta.discourse.org/t/difficulties-in-correctly-adding-external-javascript/118099/4 "2019-11-05T03:33:12Z")

</div>

Evidently my search skills failed me. There was already [a thread that existed asking about RefTagger](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202), with an [answer there that works](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202/7).

I was indeed correct in thinking that `decorateCooked()` would be used. All credit to @david who posted the solution on the thread linked above! (Also credit to @thwright for finding this older solution and letting me know about it).

Here’s the code I’m putting in `</head>` via the theme customization, with some of the specific RefTagger settings:

```plaintext
<script type="text/discourse-plugin" version="0.2">
window.refTagger = {
	settings: {
		bibleVersion: "NKJV",
		convertHyperlinks: false,		
		roundCorners: true,
		socialSharing: [],
		tagChapters: true
	}
};

let loadScript = require('discourse/lib/load-script').default;

api.decorateCooked($elem => {
    loadScript("//api.reftagger.com/v2/RefTagger.js").then(()=>{
        window.refTagger.tag($elem[0]);    
    })
});
</script>

```

---

_[View the full topic](https://meta.discourse.org/t/difficulties-in-correctly-adding-external-javascript/118099)._
