Programmable Media

CDN delivery options

Last updated: Nov-06-2024

Cloudinary incorporates robust Content Delivery Network (CDN) features to efficiently distribute media assets across the web. With strategically located edge servers worldwide, including leading CDNs such as Akamai, Fastly, and Cloudflare, Cloudinary reduces latency and improves overall performance of images, videos, and other media.

This section delves into various special CDN delivery options provided by Cloudinary that enable you to further customize content delivery strategies based on your technical requirements and preferences.

Asset versions

By default, Cloudinary assigns a randomly generated unique public ID to each uploaded media asset. Alternatively, you can either define your own custom public ID or one based on the original file name of the uploaded image. If you upload an image with a public ID that already exists, the file will be overwritten. Keep in mind though that the CDN may already contain a previously cached copy of the older image.

To force the CDN to display the latest uploaded image, you can add a version component to Cloudinary's URLs. The version value is returned by Cloudinary as part of the response of the image upload, and represents the timestamp of the upload. Adding the version component to URLs can be done by setting the version parameter (v in URLs), for example:

sample image with version

As an alternative to using versions, you can set the invalidate parameter to true while uploading a new image in order to invalidate the previous image throughout the CDN. It usually takes between a few seconds and a few minutes for the invalidation to fully propagate through the CDN, while the version component takes effect immediately.

Notes
  • There are also a number of other important considerations when using the invalidate functionality. For details on invalidating media assets, see Invalidating cached media assets on the CDN.
  • You cannot use 'v' followed by numeric characters as the name of a folder when using the legacy fixed folder mode.

Private CDNs and custom delivery hostnames (CNAMEs)

The default Cloudinary shared CDN distribution is https://res.cloudinary.com. Thus, the default delivery URL for Cloudinary product environments uses the format:

https://res.cloudinary.com/<cloud_name>/...

Cloudinary also supports private CDN distribution configurations. In this case, your asset delivery URL will follow the format:

https://<cloud_name>-res.cloudinary.com/...

For example:

https://demo-res.cloudinary.com/image/upload/sample.jpg

Additionally, Cloudinary supports defining a custom delivery hostname (also known as a CNAME) for relevant customers. In this case, your asset delivery URL will follow the format:

https://<your custom delivery hostname>/...

For example:

https://www.example.com/image/upload/sample.jpg

Note
Private CDN distributions and CNAMEs are available only for Cloudinary's Advanced plan and higher, and require a small setup on Cloudinary's side. Custom delivery hostnames (CNAMEs) also entail an additional cost. Contact us for more details.

SDK configuration for private CDNs and custom delivery hostnames (CNAMEs)

By default, when you use Cloudinary SDKs to generate delivery or transformation URLs, they generate them in the default format.

If you are using a private CDN or custom delivery hostname, make sure to define the private_cdn or secure_distribution/cname configuration parameter, so that the SDK will generate your URLs correctly.

For details, see Configuration parameters as well as the Installation and Configuration section of the relevant SDK guide.

Custom favicons

If your product environment is configured with a private CDN or custom delivery hostname (CNAME), you can also set up a custom favicon. This favicon will be displayed whenever anyone views the assets you deliver in a separate tab. For example, note the custom Custom favicon logo in the browser tab of the following image:

Sample favicon

To set your custom favicon, upload a public .ico file called favicon.ico to the root folder of your product environment.

If you don't set a custom favicon, the default Cloudinary logo favicon is used.

Multi-CDN solutions

Different CDN solutions may provide better support for a particular CDN-based functionality that is important for your website or application, such as quick invalidations, video streaming capabilities, and more.

Alternatively, you may find that one CDN service best serves certain geographical markets, while another is significantly better for other locations. The same may be true for the same geography, but at different times of the day, or for a variety of other variables. Therefore, you could potentially optimize your page load time for each user by using different CDN services for different user requests.

If your account is on an Enterprise plan, you can optionally take advantage of one of the following solutions to ensure that your resources are delivered via the CDN that bests fits the needs of your application and your users:

  • Dynamic multi-CDN switching: Uses real-time data to automatically select the best performing or most appropriate of the supported CDN services for every user request. This automated CDN switching service routes users based on geography, HTTP round-trip-time (RTT), and a variety of other variables, and directs each user to a specific web server based on intersections between server load and geography, while avoiding CDNs that are experiencing temporary outages or lowered availability. It gathers this data on an ongoing basis so that it is ready to make the best real-time routing decision each time a request comes in.

    • Take a look at the Multi-CDN Demo page to see how long the same resource takes to deliver to your browser or to a variety of geographies via different CDN services, and how quickly you can deliver that same resource via the multi-CDN switching feature.
    • This service includes real-time monitoring that can provide insights about how improvements in your page load time influence user behavior KPIs such as visit length and conversions.
  • Smart CDN selection: Cloudinary experts help you determine which of the supported CDN services is the best fit for your required features and target audience. In some cases, it may even be determined that certain types of resources should be delivered through one CDN service, and the remainder through another. Additionally, if it's determined in the future that another CDN service could better serve your content, Cloudinary transparently implements the new configuration and mapping behind the scenes.

In both of the above options, Cloudinary handles the required CDN configurations and the mappings between CDN domains and the public Cloudinary domain, so that the resource URLs in your site or app never need to change.

These multi-CDN features are available only to Cloudinary customers with Enterprise plan accounts, and the dynamic multi-CDN switching feature affects pricing. Contact our Enterprise support and sales team or your CSM for additional details.

Fast API

Important
This feature is only available for Enterprise Customers at an additional cost. Please contact support to enable this feature.

In general, repository operations like upload, data enhancement, search, administration, and delivery of assets operate from regional data centers in the US, EU, and AP. By default, only Cloudinary delivery operates to local CDNs, and for companies with a global user base spread across different regions, other repository operations that operate through far away data centers using default network protocols can be slow and unacceptable.

To address this issue, the Fast API feature provides network traffic acceleration to and from their data centers. Fast API utilizes the capabilities of a Content Delivery Network (CDN) and customers are able to connect to the closest Point of Presence (PoP) within the CDN. Enhanced internal connectivity between the CDN and Cloudinary backend provides an extra performance enhancement.

By default, all our APIs receive improved performance, and this would be noticeable in the case of the Upload API, particularly when making large uploads in chunks. For other APIs, the benefits may be less noticeable, unless a specific endpoint is called frequently with high concurrency.

Using Fast API

To enable the feature you need to set the upload_prefix configuration parameter when configuring your Cloudinary SDK to:

For customers using the EU or AP data centers, use the specific hostname, respectively:

SEO-friendly media asset URLs

Image and video URLs are specified in the source code of HTML pages and are leveraged by search engines to understand the media asset's content. Concise and descriptive image and video file names are better for search engines to extract information about a media file, therefore supporting your site's SEO ranking.

SEO starts with the ability to define custom public IDs while uploading media assets which can be as descriptive as necessary. Cloudinary can help make your image and video URLs more SEO friendly in a few other ways:

Tip
If you're on the Advanced plan or higher, you can also make your URLs more SEO friendly by using a custom delivery hostname (CNAME) for your URLs instead of the shared res.cloudinary.com. The dynamic SEO suffix and CNAME features can also be used together, for example:

https://<mydomain.com>/images/t8sn7wg4jd74j/basktetball-game.jpg

For more information on creating SEO friendly URLs, see the article on How to dynamically create SEO-friendly URLs for your site's images.

Root path URLs

The Root Path URL feature allows you to create shorter image URLs for delivering uploaded images. The default Cloudinary resource delivery URL includes the resource type and type parameters, for example, /image/upload. With Cloudinary's Root Path URL feature, the resource type and type parameters are set to the default values 'image' and 'upload' respectively, which means that any URL without the resource type and type parameters will automatically default to using those values.

For example, the default delivery URL for the sample image in JPEG format is normally:

https://res.cloudinary.com/demo/image/upload/sample.jpg

The delivery URL using the Root Path URL feature for image uploads is:

https://res.cloudinary.com/demo/sample.jpg

Both the URLs above deliver the same uploaded image.

Dynamic SEO suffixes

The dynamic SEO suffixes feature allows you to dynamically add a descriptive suffix to the public ID in the delivery URL. This can be useful:

  • If the asset was not given a suitable public ID during the upload process.
  • To support different languages for describing a single asset.
  • To reflect specific content on certain pages.

Note
Using this feature when delivering a URL does not incur additional transformation counts as the suffix is resolved on the CDN layer.

Even when transformations are applied, if you deliver the identical transformation URL multiple times, where only the SEO suffix differs, then only the first delivered (or eagerly generated) of those URLs, regardless of SEO suffix, is charged for initially generating the transformed asset.

To add a dynamic SEO suffix, the asset type and delivery type elements of the URL need to be merged into a single component:

  • For assets stored using the upload delivery type:
    • replace /image/upload with /images
    • replace /video/upload with /videos
    • replace /raw/upload with /files
  • For private image uploads, replace /image/private with /private_images
  • For authenticated image uploads, replace image/authenticated with /authenticated_images.

Afterwards, any custom suffix can then be dynamically appended to the public ID by adding a slash (/) and the SEO name.

Note
Currently, private and authenticated videos do not support SEO suffixes.

For example the default delivery URL for the t8sn7wg4jd74j image in JPEG format is:

https://demo-res.cloudinary.com/image/upload/t8sn7wg4jd74j.jpg

The delivery URL with the suffix basketball-game added to the public ID is:

https://demo-res.cloudinary.com/images/t8sn7wg4jd74j/basketball-game.jpg

In the URL below, the same image is given a suffix in Spanish:

https://demo-res.cloudinary.com/images/t8sn7wg4jd74j/baloncesto-juego.jpg

All the URLs above deliver the same uploaded image.

Generating URLs with SEO suffixes using SDKs

To generate a URL with an SEO suffix using an SDK, pass the relevant url_suffix/suffix configuration parameter. The SDK will then generate the URL with correct merged asset type & delivery type component and append the specified suffix.

The example below shows a URL with multiple chained transformations and a Spanish SEO suffix.

Spanish SEO suffix

Error handling

If you have a problem when accessing a Cloudinary transformation URL (e.g., a blank result in your browser), it might be a simple matter of using the wrong transformation syntax. To understand more, check the X-Cld-Error HTTP response header which is where Cloudinary reports any errors it encounters (e.g., invalid syntax, invalid parameters, limit issues, etc.).

For example, trying to access the following URL would result in a X-Cld-Error: Invalid width - abc error, as the width parameter is used with an integer value and not a string:

https://res.cloudinary.com/demo/image/upload/w_abc/sample.jpg

To view the X-Cld-Error header on a Chrome browser for example, select Developers Tools from the View menu. Then select the Network tab, refresh your page, click on the image name with the 400 status code and look for X-Cld-Error under Response Headers.

Accounts on the Advanced plan or higher can also use the Cloudinary Console to see errors that were generated from API calls or delivery URL requests to your product environment. To access this report, select Reports > Error reports from the Programmable Media navigation menu in the Console. For more details, see Error reports.

Using a default image placeholder

Default images can be used in the case that a requested image does not exist. For example, a site that automatically stores user profile pictures with the same name as the user themselves, allowing you to reference the pictures by user name (unless the user has not uploaded a profile picture yet). Specify a default image to use with the default_image parameter (d in URLs) and the public ID + format of a previously uploaded image, for example, d_placeholder.png to use the image with the public ID of placeholder as the default image. Any requested transformations are also applied on the default image as well.

For example, to use the PNG image called avatar as a default image in the case that the image called non_existing_id does not exist:

avatar used as default image when requested image does not exist

The same example as above, but with transformation parameters applied to scale down to 200 pixels wide and rotate by 45 degrees:

avatar used as default image when requested image does not exist

If the public ID of the default image contains forward slashes, replace the slashes with colons (e.g., an image with public ID docs/placeholders/samples/avatar.png should be referenced as d_docs:placeholders:samples:avatar.png). The intended image should be specified with slashes as normal. For example:

avatar used as default image when requested image does not exist

Note
If the requested image does not exist and the default placeholder image is delivered instead, the x_cld_error header will also be included in the response.

✔️ Feedback sent!

Rate this page: