# How to set Cache-Control in emberjs

**URL:** <https://discuss.emberjs.com/t/how-to-set-cache-control-in-emberjs/14779>\
**Category:** Ember Data\
**Created:** [May 17, 2018, 8:43am UTC](https://discuss.emberjs.com/t/how-to-set-cache-control-in-emberjs/14779 "2018-05-17T08:43:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![khanhnguyen](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@khanhnguyen](https://discuss.emberjs.com/u/khanhnguyen)\
**Post date:** [May 17, 2018, 8:43am UTC](https://discuss.emberjs.com/t/how-to-set-cache-control-in-emberjs/14779/1 "2018-05-17T08:43:38Z")

</div>

Hi all. I’m looking for how to set Cache-Control in emberjs. Can you give me any suggestion?

Thank a lot.

---

<div class="post-metadata">

**Author:** ![ef4](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ef4/32/13470_2.png) [@ef4](https://discuss.emberjs.com/u/ef4)\
**Post date:** [May 17, 2018, 5:11pm UTC](https://discuss.emberjs.com/t/how-to-set-cache-control-in-emberjs/14779/2 "2018-05-17T17:11:17Z")

</div>

The `Cache-Control` header can be set on both requests and responses. I assume you’re asking about putting it on requests, because typically Ember is only running on the client\* and you have some other server sending responses.

To set headers on requests, it depends how you are fetching data. Ember itself doesn’t dictate that, although the typical default choice is to use ember-data (people often miss that ember-data is a totally separate library that you can choose to include or not, and Ember works just as well with raw `fetch` or `jQuery.ajax` or graphQL/apollo, etc).

Assuming you are using ember-data, you can extend your `Adapter` so that it sets headers:

```auto
export default DS.JSONAPIAdapter.extend({
  ajaxOptions() {
    let hash = this._super(...arguments);
    hash.beforeSend = (xhr) => {
      xhr.setRequestHeader('Cache-Control', 'no-cache');
    };
    return hash;
  }
});

```

* * *

- Unless you have a fastboot server, in which case I guess it _does_ make sense to ask how to set headers on responses, and [that is documented here](http://ember-fastboot.com/docs/user-guide#response-headers).

---

<div class="post-metadata">

**Author:** ![khanhnguyen](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@khanhnguyen](https://discuss.emberjs.com/u/khanhnguyen)\
**Post date:** [May 18, 2018, 1:37am UTC](https://discuss.emberjs.com/t/how-to-set-cache-control-in-emberjs/14779/3 "2018-05-18T01:37:23Z")

</div>

Thank you very much @ef4. I have a fastboot server this case. I will try to follow your suggestions, hope I can do this.
