Confusion on Cacheing and Live Reloading

I updated to 0.127.0 to play around with live reloading from a remote resource and thought I would try to get output from an RSS feed displayed on my site and updating automatically. This worked great when running my site with “hugo server” but updates stopped happening on my site when I built it to serve with nginx. I think this is because I may be lacking understanding in some core concepts.

I created a ttrsspull.html file under layouts/shortcodes to parse the output of ttrss XML:

{{ if .Get "url" }}
{{ $url := .Get "url" }}
{{ $limit := .Get "limit" }}

<div class="py-8">
    {{ with resources.GetRemote $url | transform.Unmarshal }}
    {{ range first $limit .entry }}
    <div class="grid grid-cols-1 md:grid-cols-2 bg-white shadow-lg border border-gray-200 rounded-lg p-4 cursor-pointer mb-6 md:mb-10" >
        <div class="flex flex-col p-4">
            <h2 class="text-xl font-semibold"><a href="{{ index .link "-href" }}" target="_blank">{{ index .title "#text" }}</a></h2>
            <p class="text-slate-400 muted text-sm">Author: {{ .author.name }}</p>
            <p class="text-slate-400 muted text-sm">{{ index .link "-href" }}</p>
            <p class="text-slate-400 muted text-sm">{{ dateFormat "January 2, 2006" .source.updated }}</p>
            {{/*  <p class="text-slate-400 muted text-sm">{{ .link }}</p>              */}}
        </div>
        <div class="flex justify-center items-center">
            {{ with .enclosure }}
            {{ $url := index . "-url" }}
            <img src="{{ $url }}" alt="{{ .title }}" class="object-contain max-h-72 rounded-xl" style="border-radius: 20px;">
            {{ end }}
        </div>
    </div>
    {{ end }}
    {{ end }}
</div>
{{ end }}

and called it from an md file in my content directory:

{{< ttrsspull url="https://path/to/xml" limit="5" >}}

and I thought the magic to make it work was in the config.toml file:

[httpcache]
[httpcache.cache]
[httpcache.cache.for]
includes = ['https://path/to/xml']
[[httpcache.polls]]
low  = '1s'
high = '30s'
[httpcache.polls.for]
includes = ['https://path/to/xml']

but I am missing something as it does not update when the RSS XML updates after I build the site (but it does work in my dev environment using hugo server). Can someone point me in the right direction on what I should be configuring?

Hugo is a static site generator. Once the site is built it is static. Set up a cron job or use a similar mechanism to periodically rebuild the site.

Got it. I was assuming that the release notes in Release v0.127.0 · gohugoio/hugo · GitHub pointed to new functionality that would allow more dynamic content on a Hugo site. I assume, then, the new 127 features are used for creating templated pages from remote data. If so, what would be the benefit of live reloading (trying to get more understanding of what the art of the possible is).

Live reloading occurs when running the development server. Live reloading does occur once you’ve built the site.

My limited understanding of the HTTP Cache when used in production: we pull the remote file if something has changed (based on the eTag in the response header) regardless of the maxAge of the file cache. Note that the max age of the file cache can be set in site configuration, or as an optional argument for each resources.GetRemote call.

The benefit is that we don’t have to pull, for example, a 100MB remote data file unless it has changed.

There’s more detail here:
https://github.com/gohugoio/hugoDocs/pull/2593#issuecomment-2148017176

Which, at some point, should be included in the documentation:
https://github.com/gohugoio/hugoDocs/issues/2618.

@bep can probably elaborate further, or correct my understanding of details.

1 Like

Awesome, thank you for taking the time to respond. It makes much more sense to me now and shows I really did misunderstand the point of the release.

1 Like

We have some terms that’s used about these things: Live reload, partial rebuilds …

Live reload on changes is a browser thing, and used with hugo server.

Mostly a development/content editing feature, where you get instant refreshes of changes in the browser.

But we also have

hugo -w

Which starts a Hugo watcher that rebuilds on changes.

A not uncommon setup would be to have hugo -w running on the web server and publish directly to where the files are hosted.

This would also support the new HTTP cache/remote polling.

Also, you would typically also pull/mount the source files on that web server. A related tip if you mount via e.g. NFS or Samba (neither, I believe, support OS level events on changes), start Hugo with the --poll (file polling):

hugo -w --poll 1h

Or something.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.