Early hints: how to dynamically assign hints in VCL

For the Early Hints feature to make sense, I need to update a list of hints every time a deploy happens. For example, a preload URL to a CSS file might change since the content hash was updated.

For that purpose, something like an edge dictionary makes sense, since it can be updated regardless of versions etc.

However, unless I know exactly how many resource hints there are, and what their keys are, I can’t really create the VCL for them, as there are no loops as I understand it. That prevents me from having a feature that automatically creates any resource hints I add to the HTML as ”automatic” early hints.

Is there another way that I can set a list of Link headers for early_hints? Will it accept a single arguments with a string containing multiple Link-headers, comma-separated? Or am I missing some feature of VCL that would allow me to somehow call the early_hints function with a list of arguments…?

Hey @emilbjorklund. At first glance, I think using Compute to handle the request, along with KV Store as a way to manage the Link values per-URL outside of the service code might be more flexible and maintainable than VCL-only. The community might have other ideas on how to do this within VCL though.

One pattern I’ve seen work is to create a dynamic VCL snippet with the required VCL logic and to update it when necessary. i.e. push code to Fastly rather than data.

@aspires As far as I can tell, Compute does not yet support Early Hints?

@lbrocardfastly Thanks for the suggestion - that’s currently not feasible as we deploy via Terraform, and it would be unwieldy to uppdate the VCL snippet if the content hash changes…

Anyway, I’ve since learned that it seems the Link header already supports multiple values per header, so it looks like my problem can still be solved with having e.g. one preloads key in a Dictionary (for example) containing multiple resource hints.