| description | Use edge networks to ensure the fastest delivery of content. |
|---|
Depending on the driver you use, CDN content will be served directly from the source. i.e if you're using the local file system driver assets will be served directly from there, if you're using the AWS S3 driver then images will be served directly from the bucket.
The Image Transformation endpoints, however, require some processing and as a result will use the server to mutate the image and then serve it. Whislt some caching is in place to reduce load, this does put a strain on the server, additionally a user might be geographically distant from the server.
To address this, you can leverage CDN edges, i.e a CDN service which will cache your content and serve it from a geographically close data centre to the user requesting it, and if it;'s in the cache, the request won't hit the server at all, saving you resources.
Fundamentally, configuring this is the same regardless of the CDN you wish to use, but in these examples we'll assume AWS CloudFront.
There are two distinct behaviours with regards the CDN URLs: serving and processing. Serving is simply serving the asset as is, byte-for-byte. Processsing is mutating an image asset (see Image Transformation) and serving the modified version, for example cropping.
As such, we'll need to configure an edge for each type individually as they will have different origins.
This short guide will explain how to configure two CloudFront distribution to serve both standard content and processed images.
Here we assume that we're using the Local Filesystem driver with default settings.
This distribution will use the application's assets/uploads directory as its origin. Create a new distribution, configuring it however you desire, but pay attention to the following key properties:
| Property | Value |
|---|---|
| Origin Domain Name | https://your-site.com |
| Origin Path | assets/uploads |
{% hint style="warning" %} You will likely be using the AWS S3 driver if yoiu're configuring CloudFront, so set the origin to be the S3 bucket. {% endhint %}
This instance will use the application's cdn/* URLs as its origin. Create a new distribution, configuring it however you desire, but pay attention to the following key properties:
| Property | Value |
|---|---|
| Origin Domain Name | https://your-site.com |
| Origin Path | cdn |
{% hint style="warning" %} Regardless of driver, you will use the above configurations. {% endhint %}
Once you have your Edges set up, the application will need to know about them. Set these in Admin.
- Navigate to
Settings › CDN - Navigate to the
Driverstab - Click
Configurebeside your desired driver- Now is a good time to double check that the driver is enabled
- Go to the
URLstab - Update the fields to use your newly created distributions
- There are two fields for serving, and two for processing - a secure and a non-secure version for each. We recommend using a secure URL for both values.
- Click
Save Changes
Now URLs generated by the CDN functions will use the CloudFront distributions.