While there are no strict requirements on how to use ImageEngine, below is a list of best practices to get the most out of ImageEngine. In general, these best practices will address and improve many of the “Core Web Vitals” reported in many web performance audit tools.
Always define display size of images
In your markup, you should always specify a display pixel size (width and height) in the image tags. Either by the width attribute or CSS styles. Additionally, if you’ve implemented Responsive Images on your site, include the
sizes attribute. Doing so will prevent unnecessary Cumulative Layout Shifts of the webpage.
In some cases, ImageEngine may return a bigger image than expected to cater to high DPI screens. If the design of the page expects a 400-pixel wide image and ImageEngine returns an 800-pixel wide image for devices with a pixel ratio of 2, the design may be broken if the markup does not define the display size of the image. Similar situations may occur when using Client Hints.
Consider setting a long cache TTL in the engine settings
Generally, setting a longer cache TTL in the ImageEngine User Adjustable settings. This TTL decides how long the object will be stored by ImageEngine. The minimum allowed TTL is 3600 sec. It is recommended to use 7776000 (90 days) as cache TTL.
Longer TTL lengths reduce the cache misses and also traffic to the origin, ensuring better ImageEngine performance.
Provide Origin images in high resolutions
If your publishing system or workflow supports it and based on the design of your page, origin images should be of higher resolution than are strictly needed. For example, if your design has a hero image with a display width of 1000 pixels (CSS pixels), ImageEngine will try to serve this image at 2000 pixels width for screens with a pixel ratio of 2. Because ImageEngine does not scale images up, the original image must be at least 2000 physical pixels wide in order to get the best possible quality. See also Client Hints.
Use Auto mode
In most cases using ImageEngine without directives is the best option. Only use directives for specific cases. When you use directives, some, or all, of the built-in optimization logic may not be applied. For example, if you specify
/f_webp/ all devices/browsers, even those not supporting webp, will be served a webp image.
Use Resource Hints
Resource Hints will speed up the connection to ImageEngine by telling the browser as early as possible to connect to the ImageEngine server. This way, the browser will have the connection open when it is needed later.
Preconnect helps warm up connections to cross-origin servers and can help improve metrics like Time-to-first-byte and is useful when you know an origin but not necessarily the exact URL of a resource that will be needed. For specific content where the URL is known, use Priority Hints
Resource hints are enabled in the
<head> section of your markup this:
<link rel="preconnect" href="//images.example.com">
Or alternatively in the HTTP response headers of your web server like this:
Link: <//images.example.com>; rel=preconnect
Read more about how to enable resource hints on your tech stack.
Use Priority hints
Priority Hints complement Resource Hints. They are useful for ensuring that specific important images are loaded as soon as possible, and are given priority over other, non-prioritized content.
Priority hints are a markup-based signal (available through the
priority property to influence the priority of resource fetches made for data. Priority hints can also complement preload. Take a Largest Contentful Paint image, which, when preloaded, will still get a low priority. If it is pushed back by other early low-priority resources, using Priority Hints can still help how soon the image gets loaded.
Priority Hints are available in Chrome 101 or later.
Please refer to this document for more information and in-depth discussion of the usage of priority hints: https://web.dev/priority-hints/
Use Responsive Images
The main reason why ImageEngine benefits from Responsive Images syntax is Client Hints. You can read more about Responsive Images and ImageEngine below.
w_auto directive, and the
sizes attribute is key. Here is an example:
<img src="//images.foo.com.imgeng.in/w_auto,800/http://wurfl.github.io/i/pencilsx.jpg" sizes="90vw">
or using the query string:
<img src="//images.foo.com.imgeng.in/image.jpeg?imgeng=w_auto,800" sizes="90vw">
If you need different sized images to be served, depending on viewport size, you can use media queries in the
Usually, the results are overall better when ImageEngine gets to decide how to optimize the image. That means no URL parameters or directives are required, just the plain image url:
<img src="//images.foo.com/img.png" alt="Image optimized with ImageEngine" width="100%" sizes="(min-width: 850px) 840px, calc(100vw - 10px)">
Note the presence of the
sizes attribute. When
sizes is present, the browser is able to calculate the intended display size of the image before making the request to download it. This is the prerequisite for the browser to add client hints to the request. Client hints enable ImageEngine to be much more accurate when resizing and optimizing images.
In your responsive images markup, with or without client hints enabled, it may make sense to use ImageEngine URL parameters to request specific sizes of an image:
<img src="//images.yoursite.com/camera.jpg" sizes="(min-width: 850px) 840px, calc(100vw - 10px)" srcset="//images.yoursite.com/camera.jpg?imgeng=/w_375 375w, //images.yoursite.com/camera.jpg?imgeng=/w_768 768w" alt="ImageEngine with srcset">
Note: ImageEngine will still convert to the best image format whether it is webp, jpeg2000 or something else.
Use Native Lazy Loading
Images not visible on the initial screen or lower on the page, should of course be loaded on demand.
Use Client Hints
Client Hints enable the browser to send more detailed information about what size the image should be, relative to the viewport size, actual display size, screen resolution, and network quality.
To enable Client Hints for your site you’ll have to explicitly enable it by adding the below
<meta> tag to your
<meta http-equiv="Accept-CH" content="viewport-width, width, device-memory, dpr, downlink, ect">
or adding an HTTP header in the response of the html:
Accept-CH: viewport-width, width, device-memory, dpr, downlink, ect
When the response from the webserver to the browser contains this header, the browser will send the requested client hints on all subsequent requests as feature or permission policies allows.
However, to enable the browser to send client hints to 3rd party locations like the ImageEngine delivery address, for example,
xxzzyy.cdn.imgeng.in, your server must also delegate access to the selected client hints to the ImageEngine delivery address. This is done using Permission Policies. This is yet another response HTTP header looks like this assuming the ImageEngine delivery address is
Remember to prefix the actual client hints with
ch- and use lowercase.
Using client hints and ImageEngine with responsive images will generate a perfectly sized and optimized image. However, note that the
Width header is only sent if the browser is able to determine the intended display size of the image. Hence, you must provide a
sizes attribute to the image tags. It is OK to “retrofit” responsive images by copying the value of any
width attribute (px) to the
<img sizes="100px" width="100">.
ImageEngine will only return
Width header is present in the request. If the origin image is smaller than the intended display size,
Content-DPR will be < 0 because ImageEngine does not scale images larger than the original size.
Here is an example implementation.
Read more about how to enable client hints on your tech stack.