Does hugo server remove stale files?

Does hugo server remove stale files from public/ when content is deleted?

I’m seeing what appears to be stale output while using hugo server, and I’d like to know whether this is expected behavior or if I’m missing a configuration option.

Environment

  • Hugo server

  • Linux Mint

  • Start command:

HUGO_ENVIRONMENT=development hugo server --disableFastRender

Test

  1. Create a content directory:
content/en/house/acmecorp/

  1. Hugo generates the website correctly.

  2. Delete the entire directory:

content/en/house/acmecorp/

  1. Verify it is really gone:
find content -name acmecorp

returns nothing.

  1. However, the generated directory still exists:
find public -name acmecorp

returns:

public/house/acmecorp

  1. Visiting
http://localhost:1313/house/acmecorp/

still displays the previously generated website.

If I stop the server, delete everything from public/, and restart hugo server, the URL correctly returns “Page Not Found”.

Question

Is this the expected behavior of hugo server?

Should stale output under public/ remain after the corresponding content has been deleted?

Or is there a recommended option or workflow that automatically removes obsolete generated files while the development server is running?

I’m trying to determine whether I should manually clean public/, or whether Hugo provides a built-in solution for this use case.

Neither hugo nor hugo server delete stale files. the purely generate files based on the sources/layouts/…

the only option is cleanDestinationDir but this only affects static files.

how often to purge the public directory depends on what and how much is changed. and ofc on the build time.

a stale content file is mostly harmless. there is no path from the generated pages to it anymore.

definitely before publishing a cleanup is imho mandatory.

for small projects i just always delete public each time starting the server.

Thank you irkode!

To clarify, the --cleanDestinationDir flag or cleanDestinationDir config setting operates on the public directory, but only if a staticDir exists.

Whether to remove files from the publishDir that do not exist in the staticDir when building the site. This setting will not take effect if the staticDir does not exist. Note that .gitignore and .gitattributes files, along with directories named .git, are always preserved in the publishDir.

https://gohugo.io/configuration/all/#cleandestinationdir

Also see https://github.com/gohugoio/hugo/issues/8433.