# Custom javascript in \<head\> disappear

**URL:** https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356
**Category:** Development
**Created:** [March 15, 2020, 4:18am UTC](https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356 "2020-03-15T04:18:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ares-X](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ares-x/32/172823_2.png) [@Ares-X](https://meta.discourse.org/u/Ares-X)
#### Post date: [March 15, 2020, 4:18am UTC](https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356/1 "2020-03-15T04:18:16Z")

</div>

Discourse Version: 2.4.1

i updated discourse to the latest version，then i found some javascript added in `<head>` doesn’t show in html source  
for example,the google analytics script was added in `edit CSS/HTLM`

 ![image|](https://global.discourse-cdn.com/meta/original/3X/3/d/3d176a8f4f6a9204e10de8f3375cf9c012d17fd4.png)

Why does this happen，i’m very confused

---

<div class="post-metadata">

### Author: ![Ares-X](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ares-x/32/172823_2.png) [@Ares-X](https://meta.discourse.org/u/Ares-X)
#### Post date: [March 15, 2020, 4:32am UTC](https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356/2 "2020-03-15T04:32:57Z")

</div>

if i make the `<script>` wrong ,such as `<script123>` , then those code will show

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/d/2d31d37a808eea6bc18b4898ae5613bb9e62ef54.png)

if i change it back to normal `<script>`, disappear again

---

<div class="post-metadata">

### Author: ![Johani](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/johani/32/176920_2.png) [@Johani](https://meta.discourse.org/u/Johani)
#### Post date: [March 15, 2020, 5:04am UTC](https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356/3 "2020-03-15T05:04:47Z")

</div>

It does not “disappear” it’s still there. What happens is that we pull all inline scripts and put them in one file for your theme.

[discourse/app/models/theme\_field.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/models/theme_field.rb#L73-L128)

So, if you search the page-source for `theme-javascript` you should see something like this

![theme javascript file](https://global.discourse-cdn.com/meta/optimized/3X/d/7/d788dba8a0c0e0b9a4cb4eb89fe3028cfe03a685_2_689x31.png)

This file will contain all of your inline scripts.

Also, Discourse has native support for Google Analytics, so why not use that?  
Search the settings for `Analytics`

---

<div class="post-metadata">

### Author: ![Ares-X](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ares-x/32/172823_2.png) [@Ares-X](https://meta.discourse.org/u/Ares-X)
#### Post date: [March 15, 2020, 5:47am UTC](https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356/4 "2020-03-15T05:47:10Z")

</div>

ok,thanks,i will try it

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [March 9, 2024, 8:11am UTC](https://meta.discourse.org/t/custom-javascript-in-head-disappear/144356/6 "2024-03-09T08:11:35Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
