Varnish offers a multitude of modules that extend standard VCL capabilities for specific use cases and improve the overall user experience. These modules are written in C, and we call them VMODs for short. You can see the full list here.
With Varnish Enterprise’s extensive collection of supported VMODs, it may not be immediately obvious whether there is one for your intended use case. To remedy this, each month we’re going to highlight an unsung VMOD and show what it’s all about. You’ll hopefully come away with a better understanding not just of how a particular VMOD can help your caching operations, but also the sheer breadth of Varnish Enterprise’s capabilities.
We’re starting off our VMOD in the spotlight series with the accept VMOD. This video breaks down the core concepts behind the VMOD:
The accept VMOD sanitizes content negotiation headers. These are HTTP request headers emitted by your browser or web client that specify which forms of content would be acceptable to receive from the web application. Or in other words, in cases where there are multiple versions of a piece of content, these headers indicate the user’s preference as to which one they want to see. The web application reads these headers and negotiates the format and language of the content to be sent.
It is important that Varnish sanitizes these headers; otherwise we could end up with many copies of the same content in the cache. In this way, accept is about content deduplication.
A common use case is to leverage the value of the Accept-Language request header to offer multilingual content for the same URL. From a caching point of view, it is important that a cache variation is created for each value of that header.
The origin server can send the following response header that instructs Varnish to create cache variations based on the value of the Accept-Language header:
The problem is that the Accept-Language header can contain too many different variations.
Here’s one example, coming from a colleague’s browser:
But then another colleague has the following value in their browser:
The accept VMOD will transform that value into a single language, based on a list of supported languages. If the preferred language is not allowed by the accept VMOD, a fallback language is selected.
Once you have sanitized the Accept-Language header, you can safely vary on that header, knowing there will only be a limited amount of variations.
Find out how to use accept VMOD on our Documentation portal here. We’re always available to talk Enterprise VMODs too, simply get in touch below: