Serve static (e.g js, css) and media assets from CDN

It’s the first time I am learning about SSG. I am coming from the django world where we push all css, js and media files to CDN and serve from there.
I wish I could do it with Hugo as well. Is it possible to push the assets to i.e Spaces or S3 when commiting to github and serve these files from there during production?

Use a post-commit hook to upload the static dir to another server.

1 Like

GitHub Actions are ideal for this. . .

1 Like

I kinda figured that any CI/CD can push the content to external servers. But what should I do to make Hugo understand that the media comes from the CDN? Do I change the config ?

No, nothing particularly, assuming you’re coding your site in a sensible way :slight_smile:

in other words, don’t hard-code urls, use the relURL and absURL functions, if you really need to string concatenate a url, use baseURL. This is pretty much the “best practice” that you’ll see all over the documentation and examples in the docs. For images and stylesheets, use the assets and/or static dirs, and access it via the recommended Hugo functions. If this sounds complicated, don’t worry, if you’re just following the tutorials and help docs, you’re already doing the right things!

if you do all of this Hugo doesn’t need to understand that the media lives elsewhere - everything is relative to the site root.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.