How EdgeScript works

更新时间:
复制 MD 格式

EdgeScript (ES) scripts work the same as the standard configurations specified in the CDN console — they process requests sent to CDN points of presence (POPs).

How it works

When a CDN point of presence (POP) receives a request, it processes that request using two sources of logic: the standard configurations in the Alibaba Cloud CDN console and any ES scripts you have deployed. ES scripts run inside the request processing pipeline, at a position you choose.

CDN

Scripts are managed per domain name. Each script runs when its conditions are met and executes at the position (head or foot) and priority you configure.

Execution positions

ES scripts run at two positions in the request processing pipeline: head (before the CDN console configurations are applied) and foot (after they are applied).

ES

Choose a position based on what your script needs to do:

Position Runs Use cases
head Before CDN console configurations Authentication, blocking, throttling
foot After CDN console configurations Cache settings, back-to-origin authentication, A/B testing

Video Tutorial

Note

This video usesCDNexplanation as an example,and also applies to Dynamic Route for CDN。

This video mainly introducesEdgeScript:

  1. EdgeScript user scenarios(complex business requirements,general feature configurations cannot meet the requirements,requiring custom configurations)。

  2. Alibaba CloudCDN provides three types of configuration features with different flexibility levels、 and different usage difficulties(EdgeScript has the highest configuration flexibility,but has a relatively higher learning curve)。

  3. What isEdgeScript?

  4. EdgeScript capabilities。

  5. EdgeScript technical principles。

  6. EdgeScript use cases。

Script priorities

When multiple scripts are assigned to the same position (head or foot), priorities determine the execution order.

Rule evaluation

Each ES script contains rules that define when the script acts on a request:

  • A rule hits when the rule contains if condition {} and condition evaluates to true.

  • A rule does not hit when condition evaluates to false, or when the rule contains no if condition {} syntax.

Functions in a script run only when their conditions are met.

Script termination

For scripts running at the same position, you can configure a script to stop execution of subsequent scripts once it has run. This lets you short-circuit the processing pipeline.