# Il Javascript nel componente del tema viene eseguito solo una volta?

**URL:** https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202
**Category:** Support
**Created:** [10 Gennaio 2019, 3:52pm UTC](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202 "2019-01-10T15:52:05Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [10 Gennaio 2019, 6:54pm UTC](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202/7 "2019-01-10T18:54:44Z")

</div>

Looks like `refTagger` requires a variable to be set on the `window` object before the script is loaded, which isn’t possible by using multiple script tags (any inline scripts are extracted and executed at the end). This method works - using our `loadScript` function:

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

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>

```

 ![28](https://global.discourse-cdn.com/meta/original/3X/7/6/7673d84869c178e09da766575063a56d00296ab1.png)

---

_[View the full topic](https://meta.discourse.org/t/javascript-in-theme-component-only-runs-once/106202)._
