If you've worked on an Experience Builder project recently, you've probably come across the need to implement a custom domain for the site so you get something that matches more closely to the brand you're working with.
In this article we're specifically going to talk about serving your domain with Salesforce CDN, so make sure you're trying to do that approach before proceeding!
Why should you consider using this option when setup up a custom domain?
Caching on our CDN improves your site’s performance and scale. When your users access a site served by the Salesforce CDN, cached content is served directly from CDN servers. CDN servers are distributed globally and are often closer to your users than Salesforce servers. Because cached content is served directly from CDN servers, your users experience faster load times routinely and in times of high traffic. CDN caching can work with browser-side caching, which also improves performance.
(Source: https://help.salesforce.com/s/articleView?id=sf.community_builder_cdn_considerations.htm&type=5)
For more information on the pre-reqs for using the CDN: https://help.salesforce.com/s/articleView?id=sf.community_builder_cdn_prerequisites.htm&type=5
Custom Domain with Salesforce CDN
This blog is intended to supplement the information that can be found in the Salesforce documentation around serving a custom domain - https://help.salesforce.com/s/articleView?id=sf.domain_mgmt_domain_config_options.htm&type=5
While this document goes through the different options and at a high level explains what is needed, I think there are a few aspects that could be clearer about how to do this with a sub-domain and also what exact records are needed when you're configuring the DNS on your domain.
Step 1 - Choose the domain type
A crucial decision in starting the process is deciding if you plan to use a full domain like www.example.com or if you plan to use a sub-domain like shop.example.com.
There are valid use cases for both and it will depend on the site you are building and how it connects to your larger companies brand.
Step 2 - Configure your DNS
Setting up your site with the Salesforce CDN choice requires a slightly different setup on the DNS side. This is mentioned in the documentation but in my opinion it’s confusing, so here’s a very explicit table of exactly what you’d need to setup for the sub-domain option. In this example we'll use shop.salesforce-mojo.com as an example URL (this shop doesn't actually exist :) but maybe someday):
# | Type | Name | Target (Value) |
1 | CNAME | shop | shop.salesforce-mojo.com.[ORG ID].live.siteforce.com. |
2 | CNAME |
A few important things to note about these records
Notice how there is not one but two records! They both are mandatory and you will not be able to create the domain in salesforce with both.
Replace the entire string [ORG ID] with your own org, this is pretty easy to find because if you go into Setup > Domains then this information will be printed at the top of the page
Ensure you have the periods in the proper location in both the name and target depending on which option you choose
Once you have done this it may take some time to propagate throughout the network, I was recently doing this on a domain served by GoDaddy and it took only about 2 minutes before I was able to create the domain in salesforce successfully. However, in some cases, this may take upwards of 48 hours.
Step 3 - Setup your domain in Salesforce
Now that you have your DNS taken care of, we're off to Salesforce! Login as an Administrator, navigate to Setup and search 'Domains'. Once you're on the domains page you'll see a screen like this image below.
Make sure you click the second option in the screenshot, 'Serve the domain with the Salesforce Content Delivery Network (CDN)'. Fill in your domain name in the top input, in our example that would be 'shop.salesforce-mojo.com'. Now click 'save'
If you've missed a DNS record, or setup them up incorrectly, then you might get an error that look similar to the image below. Make sure you take a look at the description it populates at this point because it typically will give you a good idea of what you're missing.
Once you've successfully saved your domain, it'll take several hours for the domain to provision. Once provisioned, you'll receive a notification from Salesforce and this will give you the ability to actually associate this domain with an experience builder site.
Step 4 - Attach your domain to the site
Below you can see what the domain looks like when i've associated it with a Commerce Cloud site, but any experience cloud site will look the same but possiblity with different paths based on what you need.
Now you have a successfully attached domain to your site and if you navigate to your domain your experience builder site will be serviced from that new domain, congrats!