With Akamai it seems impossible to make use ImageEngines “prefixing mode” in the Luna control panel. Therefore, the real origin must be defined in ImageEngine (see Preparation) From Akamai perspective, ImageEngine is the origin from images.
Preparation
- Register a domain name in the admin panel at control.imageengine.io. This domain will get a canonical name like “images.foo.com.imgeng.in”.
- Configure this domain with the actual origin where your original images are located.
- Verify the setup by accessing images like this: images.foo.com.imgeng.in/path/image.jpeg
- images.foo.com.imgeng.in will be used in the Akamai setup as the origin for images.
Akamai configuration
Akamai does not have a configuration language or scripting language, so all configuration is done in a user interface.
Configuration is done in the Luna panel: https://control.akamai.com/ in the Property Manager Editor
Set variables
Click the Add Variable button, and add the following variables (automatically prefixed with PMUSER_):
Note: Akamai already has WURFL installed. We’ll use WURFL to decide the default image size based on screen resolution capabilities.
Name | Initial value | Description |
WIDTH |
/w_2560 |
Maximum Width of image |
FORMAT |
/naf_jp2_jxr_webp_mp4 |
Image format specification |
IE_PROTO |
1.001 |
ImageEngine protocol version. |
VERSION |
1 |
Version of the Akamai configuration (for debugging) |
CH_DPR |
1 |
DPR from Client HInts |
CH_WIDTH |
Width from Client Hints | |
DPI_CL |
/dpicl_1 |
DPI Class 1-4 |
CH_VP |
Viewport Width from Client Hints | |
WURFL_DEVICE |
Device info from Akamai WURFL | |
WURFL_WIDTH |
Screen width from Akamai WURFL instance | |
WURFL_IS_WIRELESS |
"false" |
Device class from Akamai WURFL instance |
WURFL_HEIGHT |
Screen height from Akamai WURFL instance |
Setting up origin
The domain name created in the ScientiaMobile admin panel (see Preparations) will act as the origin in the Akamai configuration:
Even if ImageEngine is specialized to optimize image traffic, ImageEngine will also handle non-image traffic. For example, if you serve all assets (images, JavaScript and CSS, from the same host it is safe to serve this through ImageEngine too. However, in many cases image traffic must be isolated first and then optimized by ImageEngine:
# Isolating the image traffic
- Log on to https://control.akamai.com, select your property and add a Blank Rule Template. You can name it “ImageEngine”
- Click “Add Match” and add a test on file image extensions. Or if you have other ways of identifying images, this is also fine. It is ok if some non-image files slip through. ImageEngine will serve this too.
if [File Extension] [matches one of] ["jpeg","png","jpg","gif","webp","svg"]
- Add a behavior to append ImageEngine directives in the url which Akamai will request images with.
- Select Regular Expression Replacement
- Input
(^.*)
to find end of line - input
$1?imgeng={{user.PMUSER_FORMAT}}{{user.PMUSER_FORMAT}}{{user.PMUSER_DPI_CL}}
. - Add behavior to Modify Outgoing Request Header
- Action: Add
- Select header name: Other
- Custom header name :
x-ie-proto
- Header Value:
{{user.PMUSER_IE_PROTO}}
- Add behavior to Modify Outgoing Request Header
- Action: Add
- Select header name: Other
- Custom header name :
x-ie-cdn-config-v
- Header Value:
{{user.PMUSER_VERSION}}
- Add behavior to Set Variable
- Variable:
PMUSER_WURFL_IS_WIRELESS
- Create Value From: Device Profile
- Operation: None
- Device Attribute:
is_wireless
- Variable:
- Add a child rule named “Set Width”
- Add a Match for Variable
- Select
PMUSER_WURFL_IS_WIRELESS
- Operator: is
- Expression: true
- Add a Set Variable behavior to the “Set Width” rule
- Variable:
PMUSER_WURFL_WIDTH
- Create Value From: Extract
- Get Data From: Device Profile
- Operation None
- Device Attribute:
resulution_width
- Variable:
- Add a Set Variable behavior to the “Set Width” rule
- Variable:
PMUSER_WURFL_HEIGHT
- Create Value From: Extract
- Get Data From: Device Profile
- Operation None
- Device Attribute:
resulution_height
- Variable:
- Add a Set Variable behavior to the “Set Width” rule
- Variable:
PMUSER_WIDTH
- Create value from: Extract
- Get data from : Device Profile
- Operation: Substitute
- Regex:
(^.*)
- Replacement:
/w_$1
- Device Attribute:
resolution_width
- Variable:
- Add a child rule named “check height” to the “set width” rule
- Add a match for the variable
PMUSER_WURFL_WIDTH
:if [PMUSER_WURFL_WIDTH] is less than PMUSER_WURFL_HEIGHT
- Add a set variable behavior
- Variable: PMUSER_WIDTH
- Create Value From: Expression
- Expression:
{{user.PMUSER_WURFL_HEIGHT}}
- Operation: Substitute
- Regex:
(^.*)
- Replacement:
/w_$1
- Add a child rule named “check if empty” to the “set width” rule
- Add Match for variable
PMUSER_WIDTH
if [PMUSER_WIDTH] is empty
- Add Match for variable
- Add a Set Variable behavior
- Variable:
PMUSER_WIDTH
- Create Value from: Expression
- Expression:
/w_1080
- Operations: None
- Variable:
- Add a child rule named “set dpiclass” to the ImageEngine rule
- Add a Match for Request Header
if [DPR] exists
- Add a Match for Request Header
- Add a Set Variable behavior
- Variable:
PMUSER_DPI_CL
- Create Value From: Extract
- Header name:
DPR
- Opeartion: Substitute
- Regex:
(^.{0,1})
- Replacement:
/dpicl_$1
- Variable:
Supporting auto jpeg 2000 conversion
- Add a new child rule to the ImageEngine rule, name it “jpeg2000”.
- Add a Match for file extension and check if extension is one of jpg or jpeg:
if [File Extensions] is not one of ("jpeg","jpg")
- AND a match for
if [Request Header] "Accept" is not one of "*image/webp*"
- AND a match for
if [Request Header] "Accept" is not one of "*/*"
- Important: click the gear and check the “wildcards in value” box
- Important: click the gear and check the “wildcards in value” box
- Add a new child rule the “jpeg2000” called “jpeg2000 UA”.
- Add a match for User-Agent:
if [User-Agent] is one of ("*Safari/*") \
AND a match forif [User-Agent] is not one of "*Version/1.*","*Version/2.*","*Version/3.*","*Version/4.*","*Version/5.*","*Edge/.*"
(Remember to check the “wildcards in value” box in the match settings.)
AND a match forif [User-Agent] is one of ("*AppleWebKit/*") \
AND a match forif [User-Agent] is not one of "*Windows NT*","*Chrome/*"
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_FORMAT
- Create value from: Expression
- Expression:
/naf_jxr_mp4_webp
- Operation: None
- Variable:
- Add another child rule to “jpeg2000” and name it “jpeg2000 Accept”
- Add a match for Accept request header:
if [Accept] is one of *image/jp2*
- Add behavior “Set Variable” with these parameters
- Variable:
PMUSER_FORMAT
- Create Value From: Expression
- Expression:
/naf_jxr_mp4_webp
- Operation: None
- Variable:
Supporting auto webp conversion
- Add a new rule under the ImageEngine rule, name it “webp”.
- Check the request header for the occurence of “image/webp”
if [Accept] is one of *image/webp*
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_FORMAT
- Create value from: Expression
- Expression:
/f_webp
- Operation: None \
- Variable:
Supporting auto gif to mp4 and animated webp conversion
- Add a new rule under the ImageEngine rule set, name it “gif”.
- Add match for gif file extension:
if [File Extension] is one of "gif"
- Add a Set Variable behavior with these values:
- Variable:
PMUSER_FORMAT
- Create value from: Expression
- Expression:
/f_gif
- Operation: None
- Variable:
- Add a new child rule under “gif”, mane it “mp4 Safari”
- Add match for User-Agent (remember to adjust “Allow wildcards in value” in settings):
if [User-Agent] is one of "*Safari/*"
- AND Add match for User-Agent (remember to adjust “Allow wildcards in value” in settings):
if [User-Agent] is one of "*Version/1?/*"
- AND Add match for User-Agent (remember to adjust “Allow wildcards in value” in settings):
if [User-Agent] is not one of "*Version/1.*","*Version/10*","*Version/11*", "*Edge/*"
- Add a Set variable behavior with the following parameters
- Variable:
PMUSER_FORMAT
- Create value from: Expression
- Expression:
/naf_awebp_jxr_webp
- Operation: None
- Variable:
- Add a new child rule to “gif”, name it “animated webp”
- Check the request header for the occurence of “image/webp*”
if [Accept] is one of *image/webp*
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_FORMAT
- Create value from: Expression
- Expression:
/f_webp
- Operation: None
- Variable:
Supporting Client Hints
Client Hints are supported by Chrome and sent to origin domains if opted in. See ImageEngine documentation for more
- Add a new rule under the ImageEngine rule set, name it “Client Hints”.
- Add a match all for presence of request headers
DPR
andViewport-Width
.if [Request Header] "DPR" exists AND if [Request Header] "Viewport-Width" exists
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_CH_VP
- Create value from: Extract
- Get Data From: Request Header
- Header Name:
viewport-width
- Operation: None
- Variable:
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_CH_DPR
- Create value from: Extract
- Get Data From: Request Header
- Header Name:
DPR
- Operation: None
- Variable:
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_WIDTH
- Create value from: Expression
- Expression:
{{user.PMUSER_CH_DPR}}
- Operation: Multiply
- Operand:
{{user.PMUSER_CH_VP}}
- Variable:
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_WIDTH
- Create value from: Expression
- Expression:
{{user.PMUSER_CH_DPR}}
- Operation: Multiply
- Operand:
{{user.PMUSER_CH_VP}}
- Variable:
- Add a Set variable Header with following parameters
- Variable:
PMUSER_WIDTH
- Create value from: Expression
- Expression:
{{user.PMUSER_WIDTH}}
- Operation: Substitute
- Regex:
(^.*)
- Replacement:
/w_$1
- Variable:
- Add a new child rule to “Client Hints”, name it “width header”
- Add a match all for presence of request header
Width
.if [Request Header] "Width" exists
- Add a Set Variable behavior with the following parameters
- Variable:
PMUSER_WIDTH
- Create value from: Extract
- Get Data From: Request Header
- Header Name:
Width
- Operation: Substitute
- Regex:
(^.*)
- Replacement
/w_$1
- Variable:
- Add a new rule under the ImageEngine rule set, name it “Set Request”.
- Add a Modify Outgoing Request Path behavior wit the following parameters:
- Action: Regular EXpression Replacement
- Perl Compatible Regular Expression:
(^.*)
- Replacement:
$1?imgeng={{user.PMUSER_FORMAT}}{{user.PMUSER_WIDTH}}{{user.PMUSER_DPI_CL}}
- Occurrences: First occurrence only
- Add a Set Variable behavior with following parameters
- Variable:
PMUSER_WURFL_DEVICE
- Create value from: Extract
- Get Data From: Device Profile
- Operation: None
- Device Attribute:
brand_name
- Variable:
- Add a Set Variable behavior with following parameters
- Variable:
PMUSER_WURFL_WIDTH
- Create value from: Extract
- Get Data From: Device Profile
- Operation: None
- Device Attribute:
resolution_width
- Variable:
- Add a Modify outgoing Response Header behavior with following parameters
- Action: Add
- Select Header Name: Other
- Custom Header Name:
X-IE-CDN-DEBUG
- Header Value:
format: {{user.PMUSER_FORMAT}}, width: {{user.PMUSER_WIDTH}}, dpicl: {{user.PMUSER_DPI_CL}}, ie-proto: {{user.PMUSER_IE_PROTO}}, cfg-ver: {{user.PMUSER_VERSION}}, device: {{user.PMUSER_WURFL_DEVICE}}, wurfl-width: {{user.PMUSER_WURFL_WIDTH}}, wurfl_is_wireless:{{user.PMUSER_WURFL_IS_WIRELESS}}
Comments
0 comments
Please sign in to leave a comment.