You can create behaviors to customize how your traffic is handled by the CDNs. New behaviors can override the Default Behavior for matching traffic, as explained here.
To create a new behavior:
- Navigate to your service.
- Select the Behaviors tab.
- Click the Add New Behavior button.
- Complete the new behavior form:
- Name – Enter a name for the new behavior.
- Path Pattern – Enter a wildcard expression that identifies the paths to which the behavior will apply. For example, a behavior defined for
/static/*will apply to both/static/image.jpgand/static/example.js. - Actions – Select the actions to apply to matching traffic. Click the Add Action button to add an action. Multiple actions can be added to a single behavior.
5. Click Save.
Order of Applying Behaviors #
Behaviors are applied using a multi-match approach. This means that if a request matches multiple behaviors, all matching behaviors will be applied.
The order in which multiple behaviors are applied to a request is determined by the hierarchy of their path patterns. The Default Behavior, which applies to all traffic, is applied first. More specific path patterns are then applied according to their hierarchy.
Example #
Consider the following behaviors:
- Behavior B1 – Path pattern
/a/* - Behavior B2 – Path pattern
/b/* - Behavior B3 – Path pattern
/a/c/*
For a request to /a/c/example.html, the behaviors will be applied in the following order:
- Default Behavior
- Behavior B1
- Behavior B3
Overriding Behaviors #
Since multiple behaviors can apply to a single request, one behavior can override another.
For example, suppose Behavior A defines a cache TTL of 60 seconds and Behavior B defines a cache TTL of 120 seconds. If both behaviors match the same request, the more specific behavior takes precedence.
For example:
- Behavior A applies to
/a/*. - Behavior B applies to
/a/b/*. - The request is for
/a/b/example.html.
In this case, Behavior B is more specific and therefore takes precedence over Behavior A.
Conflicting Paths #
Multiple behaviors can be created within a single service, with each behavior identified by a path pattern.
Behaviors with conflicting path patterns cannot be created. Two path patterns are considered conflicting if the intersection between them is not empty and is not equal to either of the paths.
Example 1
- Path A –
/a/* - Path B –
/b/*
These paths are not conflicting because the intersection between them is empty.
Example 2
- Path A –
/a/* - Path B –
/a/b/*
These paths are not conflicting. Although the intersection between them is not empty, the intersection is equal to Path B.
Example 3
- Path A –
/a/* - Path B –
*.js
These paths are conflicting. The intersection between them is not empty and is not equal to either path.
For example, the object /a/example.js matches both path patterns.