Hugo creates a copy of each image for each translated version of a page

Hello everyone,

I’ve created my custom Hugo theme that supports two languages. Each post in my blog is a page bundle, that contains all the necessary information: text and images. When I publish a two languages blog post with a single image inside then this image is copied to both versions of the generated blog post (discourse doesn’t allow me to insert more than 2 links, so an example is a bit artifitial):

  • blog post: example[.]com/en/blog/2022/name/, example[.]com/blog/2022/name/,
  • two copies of the same image: example[.]com/en/blog/2022/name/01-dsc07205.jpg, example[.]com/blog/2022/name/01-dsc07205.jpg,
  • not only an original version of the image, but all the modifications are copied as well: example[.]com/en/blog/2022/name/01-dsc07205_hu70402d3e41aaca26c9feb38425d899ec_4685824_970x728_fit_q75_box.jpg, example[.]com/blog/2022/name/01-dsc07205_hu70402d3e41aaca26c9feb38425d899ec_4685824_970x728_fit_q75_box.jpg

This behaviour significantly increases storage consumption. Is it expected behaviour that any image and all its modifications are copied to each language version of the post? Or it’s a mistake in my theme? Is there a way to keep only one copy for each image in all translated versions of a post and have a link to it from all the translations? Or maybe it’s possible to tell Hugo using symlinks from translated page bundle to an original one?

In a multilingual configuration, Hugo builds each language as a separate logical site. And if you add a baseURL to each language, they become separate physical sites as well.

Hi jmooring, thank you for your answer.

Did I understand you correctly that it’s an expected behaviour? To be honest, it doesn’t seem logical to me. I don’t use custom baseURLs and for me it’s more important to don’t have content duplication rather than to be able to split different translations to independent web-sites. I don’t understand as well why one generated web-site can’t have links to another one. I mean, what the problem to have links like from the or even from, lets say,

It would be great if it had been configurable: to duplicate images between translations or to keep only one copy of each image and use cross-links between sites. Is it possible to implement it somehow with the current Hugo version?

It’s a known issue/bug that will soon(ish) be fixed.

So, @jmooring is right that we in the case where you configure it to be a “multihost setup”, we naturally need to copy the same image to each host, but that’s probably not your setup.

1 Like

Just to add to this discussion that the behavior also occurs when publishResources: false is invoked!