Search code examples
firebase-hosting

How to increase cache expiration date with firebase tools?


I cannot seem to make the max-age work properly with any file. I want to increase the expiration of the cache, and I've been trying to increase only the image time for testing purposes. Still, chrome and firefox state the max-age for the image as 3600 with this json fileImage shows the files structure and the firebase.json file


Solution

  • The source for the header isn't matching the input path of images in that folder - it needs to start with a /:

    {
      "firebase": "sistema-de-oficios",
      "public": ".",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "headers": [{
        "source": "/css/images/*.@(jpg|jpeg|gif|png)",
        "headers": [{
          "key": "Cache-Control",
          "value": "max-age=7200"
        }]
      }]
    }
    

    Also, make sure you're on the latest version of firebase-tools which is currently 1.1.4 at the time of writing.