Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cache-Control header in firebase.json not working

The Cache-Control header in my firebase.json does not seem to be working. The max-age value for all files is set to 31536000 (1 year), but when loading the page it is still set to the browser default of 3600 (1 hour).

The firebase.json file seems to abide by the firebase documentation.

{
    "hosting": {
        "public": "public"
    },
    "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
    ],
    "headers": [{
        "source": "**",
        "headers": [{
            "key": "Cache-Control",
            "value": "max-age=31536000"
        }]
    }]
}
like image 435
deleted Avatar asked Jun 30 '16 05:06

deleted


People also ask

What happens if there is no cache control header?

Without the cache control header the browser requests the resource every time it loads a new(?) page.

How do I add a cache control header?

If you want to enable Cache-Control for all files, add Header set line outside the filesMatch block. As you can see, we set the Cache-Control header's max-age to 3600 seconds and to public for the listed files.

What is Cache Control HTTP header?

Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).

How do you cache data on Firebase?

Firebase Hosting uses a powerful global CDN to make your site as fast as possible. Any requested static content is automatically cached on the CDN. If you redeploy your site's content, Firebase Hosting automatically clears all your cached static content across the CDN until the next request.


1 Answers

According to full page configuration you have to set hosting key first.

This have to work:

{
  "hosting": {
    "public": "app",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "headers": [{
      "source" : "**",
      "headers" : [{
        "key" : "Cache-Control",
        "value" : "max-age=31536000"
      }]
    }]
  }
}
like image 192
Arnold Gandarillas Avatar answered Oct 27 '22 12:10

Arnold Gandarillas