<p>This is something that is best done via server-side config. The reason is that when an image is requested, for instance, your Twig code that sets the header never gets run for that request.</p>

<p>You can see how it is done via Nginx here: <a href="https://github.com/nystudio107/nginx-craft/blob/master/nginx-partials/expires.conf" rel="nofollow noreferrer">Nginx-Craft</a></p>

<p>For Apache (don't use <code>.htaccess</code> pls) go here: <a href="https://github.com/h5bp/server-configs-apache" rel="nofollow noreferrer">html5 boilerplate apache</a></p>

CC BY-SA 4.0
2018-09-18T20:01:59.267Z
I have arcustech hosting and I reached out to them to set them up via config but  they just told me to do it via .htaccess Why do you say not to do it that way?
Danielle Frappier
CC BY-SA 4.0
2018-09-18T21:40:13.187Z
I'm probably being pedantic about it, but my reasoning is here: [Stop using .htaccess files! No, really.](https://nystudio107.com/blog/stop-using-htaccess-files-no-really) -- but you are using managed hosting where you don't have access to the server config, so you probably have no choice.
andrew.welch
CC BY-SA 4.0
2018-09-18T19:18:57.360Z
2018-09-18T19:18:57.360Z
andrew.welch
<p>I was running a page speed test and it came up that I'm not leveraging browser caching for images and such. I was hoping to use the header tag to solve this. <a href="https://docs.craftcms.com/v3/dev/tags/header.html#app" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/tags/header.html#app</a></p>

<p>Where does this go exactly? In the _layout?</p>

<headers>
Where to use {% header %}
# Where to use {% header %}

(Asked by: username_0 on 2018-09-18)

I was running a page speed test and it came up that I'm not leveraging browser caching for images and such. I was hoping to use the header tag to solve this. <https://docs.craftcms.com/v3/dev/tags/header.html#app>

Where does this go exactly? In the \_layout?

**Tags:** headers


---

## 1 answers

### Answer by username_1 on 2018-09-18. Score: 2 | Accepted answer

This is something that is best done via server-side config. The reason is that when an image is requested, for instance, your Twig code that sets the header never gets run for that request.

You can see how it is done via Nginx here: [Nginx-Craft](https://github.com/nystudio107/nginx-craft/blob/master/nginx-partials/expires.conf)

For Apache (don't use `.htaccess` pls) go here: [html5 boilerplate apache](https://github.com/h5bp/server-configs-apache)

> **Comments:**
> **username_0**: I have arcustech hosting and I reached out to them to set them up via config but  they just told me to do it via .htaccess Why do you say not to do it that way?  
> **username_1**: I'm probably being pedantic about it, but my reasoning is here: [Stop using .htaccess files! No, really.](https://nystudio107.com/blog/stop-using-htaccess-files-no-really) -- but you are using managed hosting where you don't have access to the server config, so you probably have no choice.  

---

