# Adding a Header Note section to reuse Javascript

**URL:** <https://forums.ankiweb.net/t/adding-a-header-note-section-to-reuse-javascript/20686>\
**Category:** Suggestions\
**Created:** [June 11, 2022, 7:01am UTC](https://forums.ankiweb.net/t/adding-a-header-note-section-to-reuse-javascript/20686 "2022-06-11T07:01:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juan](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/juan/32/3757_2.png) [@juan](https://forums.ankiweb.net/u/juan)\
**Post date:** [June 11, 2022, 7:01am UTC](https://forums.ankiweb.net/t/adding-a-header-note-section-to-reuse-javascript/20686/1 "2022-06-11T07:01:01Z")

</div>

I use Javascript in my notes to add functionality like formatting card tags, slightly modifying a card’s contents, etc. When a note has more than one card type and I want to reuse javascript functionality, I need to copy-paste code but that is very error-prone. It would also make it easier to maintain my notes if I can put all the javascript in one place and it’s separate from HTML, like I do now with CSS (Styling).

Would it be possible to add a “Shared Header Template” section to the Card Types editor whose contents would be wrapped around tags and rendered before the Front Template of a card at render time, a bit like how the Styling section works?

 ![Screen Shot 2022-06-11 at 08.55.52](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/2/2be94268ab48334556f86c8b3d3eb00d42aa0745.png)

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [June 11, 2022, 2:10pm UTC](https://forums.ankiweb.net/t/adding-a-header-note-section-to-reuse-javascript/20686/2 "2022-06-11T14:10:53Z")

</div>

> [@juan](#):
>
> I need to copy-paste code but that is very error-prone

One thing you can do now is putting JavaScript in a separate file in your media folder, then referencing it like this:

```auto
<script src="_file.js"></script>

```

You then only have to duplicate this line in other templates.  
Note that the filename [should start with an underscore](https://docs.ankiweb.net/templates/fields.html#static-soundsimages).

---

<div class="post-metadata">

**Author:** ![BlackBeans](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/blackbeans/32/2283_2.png) [@BlackBeans](https://forums.ankiweb.net/u/BlackBeans)\
**Post date:** [June 11, 2022, 2:18pm UTC](https://forums.ankiweb.net/t/adding-a-header-note-section-to-reuse-javascript/20686/3 "2022-06-11T14:18:59Z")

</div>

You could try using [Asset Manager](https://ankiweb.net/shared/info/656021484), which basically does what you want: every note type is given an asset collection, and for each asset (might it be JS, HTML, or whatever) you can choose where and how to insert it into a card template.
