Asset canister: HTTP headers Cache-Control and Access-Control-Allow-Origin

Is there a way to defined HTTP headers with the asset canister? Is it maybe possible to configure this dfx.json?


For performance reason, I have to define the Cache-Control headers of the icons, images, fonts and other JS assets of my web app.

These are also displayed by Lighthouse as errors, therefore, can also have an impact on the SEO ranking in addition.

If possible, it would be also nice if other headers such as Access-Control-Allow-Origin, which I use to make some icons available cross-domains, would be available.

With Firebase I currently set such headers as following in the local firebase.json configuration file:

{
  "hosting": {
    "public": "www",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "headers": [
      {
        "source": "assets/icons/**/*",
        "headers": [
          {
            "key": "Access-Control-Allow-Origin",
            "value": "*"
          },
          {
            "key": "Cache-Control",
            "value": "max-age=31536000"
          }
        ]
      },
     {
        "source": "**/*[email protected](js|css)",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=31536000"
          }
        ]
      }
]
  }
}
4 Likes

I opened a feature request in the SDK

1 Like