Using IMGIX or other CDN providers

Forgive me if I missed this in the documentation, as I though I had come across it before.

I use IMGIX for image hosting on most of my sites. The solution I’m looking for goes like this…

  1. Store image assets in the static directory

  2. When running the site locally, it loads the file from relative URL source

  3. When published to Netlify, the URL is replaced with the absolute CDN url.

Is there a way to handle this in Hugo that I am missing? Please advise.

I am not patronizing you, I am just speaking in basic terms to ensure I cover what you are asking. I will also assume you have figured out step 1 (I wasn’t clear if you were asking how, but it is just adding files to that directory).

After that, it sounds like you want to render the local version of your site linked to the static files as usual, but want to render the URL for your CDN when you publish it. Does that sound right?

I understand IMGIX has other benefits, but I wanted to point out that Netlify will likely get you the same results, if you per-processed your images.

The way I’d handle that would be with a conditional shortcode, and using a ENV or other method to show a different version in local development. See the discussions around loading analytics conditionally. :slight_smile:

1 Like

Actually, I should be patronizing myself.

In reading this I realized of course I won’t be able to take advantage of the other IMGIX features so long as they’re running locally. I think I just hadn’t had enough coffee yet.

Regardless, your message helped me get on the right track. Thank you!

1 Like