Load assets from a separate domain (CDN)

#1

How do I load my images, JS, CSS, etc from a domain which is different from the site URL? For example, if my site is example(dot)com, I want to rewrite my URLs of images, JS, etc to assets(dot)example(dot)com (to load it from a CDN)

Setting the baseURL=“assets.example.com” and canonifyURLs=true the config, changes the hrefs of anchor tags as well. So when the user clicks on links he is taken to https://assets.example.com/page which I do not want.

0 Likes

#2

You’ll need to modify the templates where your assets are references.

Not every theme will support this out of the box. Some do, however, and one can set the CDN in the config file. It is just a variable like any other, so you may customize it however you like. :slight_smile:

0 Likes

#3

You need to add CDN to Your template. for example;

<img src="https://assets.example.com{{.Params.image}}" alt="{{.Title}}">
0 Likes