Find the filesize of a resource?

I’m trying to find the filesize of a resource.

Are there any better ways to do it than using the len function like this?

len $resource.Content

This method is supposedly taxing on the memory, because it requires you to load the file into memory and count the bytes. Is there a way to read the filesize somehow from the file properties (there is no access to File from Resource type)?

No.

The next best alternative that I can come up with requires:

  1. Hard coding of the publishDir within your template
  2. Using the --renderToDisk option when running hugo server
{{ with resources.Get "a.jpg" }}
  {{ with .Resize "300x webp" }}
    {{ (os.Stat (path.Join "public" .RelPermalink)).Size }}
  {{ end }}
{{ end }}

I wouldn’t do it.