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:
I did not tried it myself but dfx v0.11.0 supports configuring assets in assets canister - i.e. configuring http headers. Therefore I think this is solved .
Hello @rbolog, we had to temporarily retract support for caching in dfx 0.11.2 – perhaps we haven’t described it well enough in our changelog, we’re sorry if this caused confusion.
Your first-described attempt will work once the feature will be enabled again:
I created the .ic-assets.json file into the xx_frontend/assets directory
with the content:
Asset canister currently undergoes a lot of changes, our hope is to make it rock solid before the end of this quarter, we’re kindly asking for your patience
not the standard asset canister provided by dfinity, but a canister that implements the http_request method. the HttpResponse type has a headers field, are those overwritten when using the .ic-asset.json file?
Hard to tell without looking at the code, but in general one would need to explicitly add support for custom http headers. This would need to happen in the canister code (see how its implemented in frontend canister: sdk/state_machine.rs at master · dfinity/sdk · GitHub) and optionally client side – see how we’ve implemented it in dfx tooling:
ah ok, the .ic-asses.json is used by the asset canister itself! i thought this file is somehow used to configure the boundary nodes, but thinking about it that doesn’t make any sense.
so when i use a old Wasm of the asset canister (pre support for .ic-assets.json) having those headers set in the .ic-asset.json won’t do nothing as there’s no support for setting headers when uploading files to the asset canister. is that correct?
correct, but you probably have to use something that uses the old ic-asset library as otherwise it’ll try to set the headers, which will get rejected because the interface does not allow headers to be set
You can since dfx 0.12.0. See the changelog entry here.
If you use the latest dfx 0.14.0 or higher the updated headers will automatically be updated. Before that you have to reinstall the canister for your new settings to apply
However, if I understood correctly, with the new certified headers feature, it will be possible also on non raw domain to specify such hearders. It was plan to roll out this in dfx v0.14.0 but there was an issue. Don’t know the currenty status. @Severin and @NathanosDev know best.
This is intentionally not working right now, the necessary changes will be deployed today.
For more context see this post: Important update for DFX v0.14.0 users