What does it do?
When a user requests an asset such as an image, CSS file, or HTML document, the request goes through the StackPath CDN edge network. If the StackPath CDN server already has the asset, it is served from cache instead of requesting it directly from the origin server. If the asset isn't cached on the CDN then the CDN pulls it from the origin server and stores it in its cache.
StackPath creates a unique cache key for each resource it stores in cache. A cache key is an "ID" for each resource that StackPath stores in cache. Keys are unique and are constructed from several variables such as protocol, like HTTP or HTTPS, and URL.
The "Dynamic caching by header" feature allows you to extend the variables used to create a cache key by adding a specific request header.
When and how should I use it?
It is possible to create specific cache keys based on request headers to deliver specific content.
For example, if your origin provides different images (same image URL/name) for mobile and desktop users, then you can create a specific cache key for those mobile users by adding a specific header. For example, using
x-mobile:true creates a new cache key for mobile asset requests, where the protocol and URL match, and the +
x-mobile:true header is present. Desktop assets will still be created from the original protocol and URL.
To implement the above functionality, create the following EdgeRules:
Create a similar rule with "iPhone" instead of "Android." This adds the "x-mobile:Android" or "x-mobile:iPhone" headers to the CDN.
Now, under the "Dynamic caching by header," add "x-mobile" as an additional cache key. Once that's in place all requests from mobile users are served from the StackPath CDN's cache.