Device Groups
Look up the fields of a device group, how a rule matches it with the device_group variable, and how a cache setting varies by it.
A device group is a name and a regular expression that an application compares with the User-Agent header of each request. A request whose header matches the expression belongs to the group, so a rule or a cache setting can treat those devices apart from the rest. Each application holds its own device groups, and Azion Console lists them in the application’s Device Groups tab.
Device group fields
A device group carries two fields that you set and an ID that the platform assigns. A rule refers to a device group by its name, and a cache setting refers to it by its ID.
| Field | Type | Description |
|---|---|---|
| Name | string | The name of the group. A rule compares ${device_group} with this name, and the cache key of a copy that varies by device ends with it. The Console shows Name must be alphanumeric for a name with other characters |
| Regular Expression | string | The expression compared with the contents of the User-Agent header, in the Match to User-Agent section of the form. It follows the PCRE standard. The Console shows Enter a valid regular expression pattern. for an expression it cannot read, and User Agent cannot contain emojis or null bytes for an expression that carries either |
| ID | integer | The identifier of the group. The cache_vary_by_devices.device_group field of a cache setting lists device groups by this ID |
User-Agent header
The User-Agent request header carries information on the client that sends the request: the browser, the operating system, the version, and the manufacturer. The header follows this syntax:
| Part | What it holds |
|---|---|
product | The product identifier |
product-version | The version number of the product |
comment | System information, the platform name and its details, and extensions |
For example, a request from Mozilla Firefox on a Windows computer carries this header:
User-Agent matching
An application compares the Regular Expression of a device group with the contents of the User-Agent header, and a request belongs to the group when the expression matches. The expression does not have to match the whole header, because a match on part of it is enough. For example, a group named Mobile with this expression matches the headers of most mobile devices:
Match order
When a User-Agent header matches more than one device group, the request takes the first group that matches, from first to last in the list of device groups. The position of the matching words inside the header does not change the result. For example, an application holds these three device groups, in this order:
| Order | Device group | Regular expression |
|---|---|---|
| 1 | Mobile | (Mobile|Android) |
| 2 | Tablet | (iPad|Android) |
| 3 | Desktop | (Chrome|Mozilla) |
A header that contains Android Tablet Mobile (Mozilla Firefox) matches all three expressions, and the request takes Mobile, the first in the list. A header that contains iPad Apple Webkit Mobile matches Tablet through iPad. The request still takes Mobile, because Mobile matches too and comes first.
Rules Engine variable
In Rules Engine for Applications, the ${device_group} variable holds the name of the device group that a request belongs to. A criterion compares it with the name of a group as its argument, so the behaviors of the rule apply only to the requests from that group. The variable requires Application Accelerator on the application.
This criterion matches a request from the Mobile device group:
| Conditional | Variable | Operator | Argument |
|---|---|---|---|
if | ${device_group} | is_equal | Mobile |
A criterion can also match a device without a device group, by comparing ${http_user_agent} with a string or a regular expression. This criterion matches a request from an iPhone:
| Conditional | Variable | Operator | Argument |
|---|---|---|---|
if | ${http_user_agent} | matches | (?i)iPhone |
For every variable and operator a rule can use, refer to Rules Engine for Applications.
Cache variation
A cache setting can deliver one version of an object to every device, or keep a separate copy for each device group it names. In Azion Console, the control is Cache vary by Devices › Behavior, in the Application Accelerator section of the cache setting. In the API, the control writes modules.application_accelerator.cache_vary_by_devices, whose device_group field lists device groups by ID. A cache setting that does not set the control carries "behavior": "ignore" and an empty device_group list. Azion CLI has no flag for device group variation.
The Application Accelerator section of a cache setting requires Application Accelerator on the application, and without it the API refuses the section’s fields with error 21013. For the values each field takes, refer to Application Accelerator settings.
Each copy that varies by device group has its own cache key, which ends in @@ and the name of the device group, such as httpwww.example.com/@@Mobile. A URL purge does not reach these copies, so purge them by cache key or with a wildcard. For the key format, refer to Cache keys. For the purge types, refer to Real-Time Purge.