MoB
MoB

Reputation: 119

Expiration header is not picked up by Firebase Hosting

My firebase.json file looks like this:

{
  "hosting": {
      "public": "public",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "headers": [{
      "source": "**",
      "headers": [{
        "key": "Cache-Control",
        "value": "max-age=960000"
      }]
      }],
      "rewrites": [ {
      "source": "**",
      "destination": "/index.html"
      }],
    "source" : "404.html",
    "headers" : [ {
      "key" : "Cache-Control",
      "value" : "max-age=960000"
    }],
    "headers": [ {
    "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
    "headers" : [ {
      "key" : "Access-Control-Allow-Origin",
      "value" : "*"
    } ]
    }],
    "cleanUrls": true,
    "trailingSlash": false
  }
}

Now checking the assets in the browser I cannot see any impact on the expiration headers sent through at all.

enter image description here

What's the matter please?

Upvotes: 0

Views: 833

Answers (1)

Michael Bleigh
Michael Bleigh

Reputation: 26333

Your configuration is malformed -- you have multiple top-level headers in your hosting configuration. It should instead look more like:

{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "headers": [
      {
        "source": "**",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=960000"
          }
        ]
      },
      {
        "source": "404.html",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=960000"
          }
        ]
      },
      {
        "source": "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
        "headers": [
          {
            "key": "Access-Control-Allow-Origin",
            "value": "*"
          }
        ]
      }
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "cleanUrls": true,
    "trailingSlash": false
  }
}

Upvotes: 7

Related Questions