# How do you force a script to refire on every page load in Discourse?

**URL:** https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856
**Category:** Development
**Created:** [11월 27, 2017, 4:36오전 UTC](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856 "2017-11-27T04:36:06Z")
**Posts on this page:** 1
**Showing post:** 16

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [3월 21, 2018, 9:00오후 UTC](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856/16 "2018-03-21T21:00:20Z")

</div>

I have been working on something that needs to be fired when entering a topic. I don’t know if this is overly complicated or the proper way to do it, but this is what I’ve found works well so far:

```plaintext
<script type="text/discourse-plugin" version="0.8.13">
    api.addPostTransformCallback((t) => {
        // post is topic post && element doesn't already exist
        if (t.post_number === 1 && $("#test-id").length == 0) {
            $(function() {
                var testText = '<h1 id="test-id">Test</h1>';
                $("#post_1 .regular.contents").before(testText);
            });
        }
    });
</script>

```

Try this out in a theme component. It will add the word “Test” to the first post in every topic.

---

_[View the full topic](https://meta.discourse.org/t/how-do-you-force-a-script-to-refire-on-every-page-load-in-discourse/74856)._
