Only copy static files actually referenced in templates or content

Hello,

I have a question regarding the way Hugo treats static files. Currently, it copies the entirety of the static folder. But ideally, it (in my opinion) should only copy the referenced files, either in templates or in content.
Is there a way to do this currently? (With an external tool for example?)

For the reference, I’m asking because I’m storing locally emojis from Openmojis (that would be 1500 svg icons), but only use a handful of them. It would be great to not have to filter manually those I use vs those I don’t and to have a build system that takes care of all this by itself.

Thanks for reading!

No.

Others may have better ideas on how to handle this.

1 Like

A static file can be referenced by anyone on the internet. No way to know.

2 Likes

Well, I understand what you mean, but in the context of Hugo, the goal of the static files is to be referenced by my website and my content, and if they are not, then I would like them to be optimized out.

In that case, maybe a whitelist kind of thing in the config file would make sense: aka “I want all the files from this folder in my public folder, but optimize the rest out.”

Just in case it’s useful for other passerbys, I’m using this procedure:

  • Start with an empty static folder
  • In the generated public/ folder, run
    ack '"/\S+\.\S+"' -oh | sort | uniq
  • This should give you a list of missing static files. YMMV