HUGO

Use `hugo --watch` in production

Hey! I’m now adding support for Micropub and some other features from IndieWeb such as Webmentions, IndieAuth and other stuff and using my website as my primary platform to publish my content and then POSSE it (post on your own site, syndicate elsewhere) on other places.

I’ve actually written a post about the journey so far and the problems I’ve been hitting. One of them is related to Hugo’s speed which isn’t usually a complaint and the theme complexity (hopefully I’ll be able to cut it down a bit soon).

As of right now, each build takes ~3s on the server and ~1s on my laptop with about ~950 posts. I don’t want to wait that much time when I just want to post a like or a repost so I was wondering if running hugo --watch in production is feasible.

During development, I’ve hit some problems with the watch mode but I think they might be related to heavy changes in the layouts and not to the website contents themselves.

What do you think? Is hugo --watch a good option for a production website that can change at any time? Or is that a bad idea?

The Hugo server is not a production server.

I would suggest that you use template metrics to identify potential bottlenecks in your project and try to optimize your templates.

1 Like

The Hugo server is not a production server.

Not hugo server --watch but just hugo --watch. I’m using Caddy as my web server.

I would suggest that you use template metrics to identify potential bottlenecks in your project and try to optimize your templates.

Yes, I’ve been looking into those but I haven’t come to a really good conclusion yet…

--watch is a flag of the command hugo server

See: https://gohugo.io/commands/hugo_server/#options

Hugo is a static site generator.

@onedrawingperday you can use --watch without the server too: https://gohugo.io/commands/hugo/#options

I’ve been using Hugo since 2014 2015 eheh

1 Like

Can you? And what does the command hugo --watch print in your terminal?

I thought that Hugo is a static site generator outputting static files under the /public/ folder.

It watches the dir and outputs to public without the server

It is a static website generator. I’m just trying to find a way to regenerate it when there might be a lot of changes in a short time period. And thus I’m thinking about either using hugo --watch or moving out of Hugo and making a really simple server-side rendering. However, I would prefer to keep my website being served with static pages.

Right I just tested the above, since I had never used hugo --watch before.

I went ahead and deleted a content file, the site was regenerated in the terminal but the generated HTML of said content file was not removed from the /public/ folder

Hopefully someone more knowledgeable than I can advice you whether running hugo --watch as a process on your server is a viable option to rebuild a Hugo project on demand.

cc: @bep

The same behavior with deletion happens when running with server too. If you try to change the content, you’ll see the correctly regenerated page. Not sure if it’s a bug or not.

The thing is that whenever the command hugo is executed the contents of /public/ are overwritten.

This does not seem to be the case with hugo --watch.

Again I was not familiar with this feature and I am a bit puzzled…

Also note that I tagged the maintainer above, hopefully if he has the time he can offer some advice.

Does this mean when someone hits the “Like” button on your post it changes the source of your website and rebuilds it?

Not quite, but you got the idea: dynamically static. See this: https://indieweb.org/POSSE :smiley: And https://hacdias.com/likes

The thing is that basically you are talking about incremental builds. You cannot achieve these just with Hugo. You might have better luck experimenting with Netlify.

There is another thread similar to yours from 2017 and it doesn’t seem like hugo --watch is the way to go.

See:

That’s sad. I’ll probably build my own platform for this. Some selfdogfooding for learning ahah. Netlify is not a static website builder, they just store your content and call whatever commands you want. I was using them, but if I do I have to wait more time: git commit & git push & netlify notices it & netlify calls hugo & hugo runs & live!

Also I saw @bep saying that it is really easy to write uneffective (ineffective?) Go templates. I wonder if there are any tips and tricks not to fall into some traps. I searched but couldn’t find any information on the subject.

From personal experience I found that too many shortcodes can slow down a project.

I have seen an improvement in performance by updating the content files of my projects to use the new Markdown Render Hooks

Too many Data files will slow down a build. There is a GitHub issue about creating Pages from Data files, in the main Hugo repo, that will be implemented at some point.

Hugo’s Related Content is the recommended way to create page links to related pages.

When using Resources to create various image sizes, committing the generated resources directory in the project’s git repo will save build time.

Template inheritance should be used throughout a project. Taking advantage of partialCached whenever possible saves build time.

Others may have more suggestions.

I didn’t say that Netlify are a static website builder. Their service offers a build image used for automated builds and incremental deployment.