# How to add \<script\> in \<header\>

**URL:** <https://www.ruby-forum.com/t/how-to-add-script-in-header/243739>\
**Category:** NGINX\
**Created:** [December 29, 2015, 10:08am UTC](https://www.ruby-forum.com/t/how-to-add-script-in-header/243739 "2015-12-29T10:08:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 29, 2015, 10:08am UTC](https://www.ruby-forum.com/t/how-to-add-script-in-header/243739/1 "2015-12-29T10:08:29Z")

</div>

I like to add the following entry:

in section. How do I do it?

Thanks!

Jim

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 29, 2015, 12:19pm UTC](https://www.ruby-forum.com/t/how-to-add-script-in-header/243739/2 "2015-12-29T12:19:55Z")

</div>

On 29 December 2015 at 11:07, 天河石 - 谢金鹏 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I like to add the following entry:
> 
> in section. How do I do it?

Okay, I will do it for you:

If you later need to remove it, it is quite simple:

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 29, 2015, 2:17pm UTC](https://www.ruby-forum.com/t/how-to-add-script-in-header/243739/3 "2015-12-29T14:17:55Z")

</div>

Hello!

On Tue, Dec 29, 2015 at 05:07:37PM +0800, 天河石 - 谢金鹏 wrote:

> I like to add the following entry:
> 
> \<script type="text/javascript" async="async"

src=“[http://www.google-analytics.com/ga.js](http://www.google-analytics.com/ga.js)”\>

> in section. How do I do it?

Assuming you want to do it using nginx, try something like this:

```
sub_filter '</head>'
           '<script type="text/javascript" async="async" 

```

src=“[http://www.google-analytics.com/ga.js](http://www.google-analytics.com/ga.js)”\>';

See docs here for details:

> **[Module ngx\_http\_sub\_module](http://nginx.org/en/docs/http/ngx_http_sub_module.html)**

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 29, 2015, 6:02pm UTC](https://www.ruby-forum.com/t/how-to-add-script-in-header/243739/4 "2015-12-29T18:02:51Z")

</div>

On Tuesday, 29 December 2015, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> [Module ngx\_http\_sub\_module](http://nginx.org/en/docs/http/ngx_http_sub_module.html)

Here is another way to do it:

> **[PageSpeed filters: the complete reference](https://modpagespeed.com/docs/filters/)**
>
> What PageSpeed filters are, how to enable them, and all 95 mod\_pagespeed filters with what each one changes.

It relies on even bigger 3rd party module that is also not included and  
compiler by default.
