Garbage collector not deleting old fingerprinted assets

I have the following scenario:

  • Assets are generated (and minified) with my own build tool and put into the /assets/dist directory.
  • I have assetDir = "./assets/dist" in my config.toml
  • CSS, for example, is called in the template by requesting the file and fingerprint it.
  • When I build my site using hugo, it is correctly generated and put into the /public folder. Assets are fingerprinted correctly.
  • When I change assets and generate the site again, new fingerprinted assets are put into /public, but the old assets stay there.

1. run

app.4b7dd44[...]aa7b86ad8.css

2. run

app.4b7dd44[...]aa7b86ad8.css // old file
app.92e5d89[...]16b924298.css // new file

I assumed that this could be solved by using hugo --gc which is recommended for image generation anyway. I thought that the garbage collector would also clean old fingerprinted assets but they are still there.

Is this intended behaviour or am I doing something wrong?


Details about the setup

Source: Github

Assets are called this way:

{{ $appcss := resources.Get "app.css" | fingerprint }}
<link rel="stylesheet" href="{{ $appcss.Permalink | relURL }}">
$ hugo env
Hugo Static Site Generator v0.55.6/extended darwin/amd64 BuildDate: unknown
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.12.5"
$ hugo --gc

                   | EN  | DE
+------------------+-----+-----+
  Pages            | 516 | 504
  Paginator pages  | 118 |  69
  Non-page files   |  64 |  38
  Static files     |  30 |  30
  Processed images | 126 |  76
  Aliases          | 205 | 229
  Sitemaps         |   2 |   1
  Cleaned          |   0 |   0
1 Like

The --gc routine is cleaning file caches, but does nothing with /public. The suggested way is to delete /public before every build.

1 Like

I use option --cleanDestinationDir . Works like a charm

4 Likes

Do not use this if the destination folder is a git repo as it will clear everything including the git files in the folder or if you have some custom files in the folder like email signature some pdf etc which are not part of Hugo project thanks