Annoying Cache

No, this isn’t an introductory post. I’m just f…ed up with Hugo’s caching and made a random account, with a random e-mail address, because I simply can’t clean, remove or ignore in any way.

I apologize if this sounds too blunt but, if you don’t like or don’t have time to read, please move along. I’m here to explain, with as many details as I can, some serious (and not new) problem with Hugo Server that I can’t post on Github otherwise it would be closed fast like a bullet.

Created two pages with a Custom Page Type for each. Everything is set correctly: FrontMatter parameter, directory structure, paths and blah, blah, blah, after all, I CAN SEE the dummy text I’ve added to the siingle.html file designed to this Page, which means the Template Lookup is working.

Well, Custom Page Types kind of overrides the .Type variable with the value set in the Frontmatter Parameter. This is so true that reading this variable in my _default/baseof.html shows me, let’s say, custom_page_one and custom_page_two

A condition that uses such variable, like this:

{{ (and (ne .Type "custom_page_one") (ne .Type "custom_page_two" ) ) }}

Should return FALSE while NOT in one of these Custom Pages, right? Well, it does! This is so true that in _default/single.html, which has an entirely different markup, the markup within the condition (here the if was committed) renders just fine.

However, viewing the source code on the browser the respective markup that I AM SEEING does NOT appear!

That’s probably your browsing caching content

I’ve NEVER seen this sort of desync between the rendered and the markup — unless, of course, if you fake it on purpose since LiveReload doesn’t reload tabs/windows prefixed with view-source://

But I’ll give you that, let’s suppose it’s browser caching, then why the very same results in 1) Private/Incognito mode or 2) Another browser with fresh-install?

ALSO I’m running Hugo Server as:

hugo server --disableFastRender --noHTTPCache --ignoreCache --renderToDisk

Meaning, all possible ways of “disabling” the cache available on the Internet, be it Hugo’s manual or random blog posts

Are you sure the conditions are correct?

Fine, fine, you don’t believe me. What about this other scenario:

<img src="/assets/images/profiles/default-{{ (index (shuffle (slice "male" "female") ) 0) }}.jpg" />

Some joke I made to show a different default user image every time the page is refreshed. That line, although just for fun, is real and was coded a week ago. While working side-by-side with Babel CLI (that’s irrelevant) — that for some reason makes Hugo server rebuild twice (and refresh browser twice) — was working correctly, but then 3 days later, when that section of the template was done (and Babel wasn’t needed anymore) and I moved on to another one, it stopped and all I could see was the “female” substring all the time (and while debugging, similar to the condition above, the shuffled slice NEVER changed)

In such cases you have to restart the server?

Yeah, I read that in some random post (here) and while it actually made the joking profile image change, it changed only once. Every subsequent refresh yielded the same substring.

Tried to restart your PC?

I did and, like the “solution” above, worked once.

But it gets better! Two days after the template rendering simply stopped rendering as they should, they started working again, all of sudden, with every refresh showing the right, updated, information.

As you might think, writing this, right now, is taking quite some time and my Hugo Server is still running and I have a few “Template changed (…) WRITE” outputs, even for files I didn’t even open this session (like one I have for Google Analytics or the 404 Page). But why is it doing that? What change could have been done in a file that hasn’t even been opened? If something was written, reloading should’ve been triggered (that’s just speculation on my part).

Long story short: Please! I’m in desperate need to get rid of this caching during development. I need to have Hugo confirming the changes I do and rebuild/reload/whatever every… single… time!

Do you have a repository that I can clone? I would like to try to replicate your problems locally. Thanks!

I may not understand what you try to do, but it’s important to understand that Hugo is a static site generator. Given the above, it’s expected that the content stays the same after a refresh. This is not a cache. This is how static site generators work.


Haha, I knew the second code, a joke that might not even get into production, would attract some attention.

Look, I’m not a rookie. I’m very aware of what an SSG is and that doesn’t justify why this line, in one single page/post, did use to change after every refresh when such refresh was caused by Babel CLI — in case anyone here doesn’t know, you code something using ESO2016-2018 syntax and Babel transpile — “converts” — it in “normal” JavaScript, regenerating the compiled file after every change thus making Hugo Server rebuild/reload/whatever.

But even if that statement regarding how an SSG works were 100% true, the very same line in a different part of the template, somewhere common to all pages/posts, like a sidebar, for example (I tested it!), would yield the randomness for different pages/posts because, after all, the sidebar would be rendered again and again for every single page/post individually and every time the shuffle function would yield — or should yield — a different result.

But fine, let’s for a moment assume that this is also false, that this line would generate one random substring for every server start and keep that one substring for every single page/post rendering. Not only this would be a killer shot for the shuffle function, making it incredibly useless, but also wouldn’t explain why it began working once again after a few days, changing after each reloads as I expected, on the same page, even without the intervention of Babel. One line of code works, stops for a few days, works, stops for a few days again.

This does not make sense! And THAT’s the true purpose of this topic.

Also, there’s no repository. All I did was create a fresh site with a random minimalist theme to test out a few ideas before I started my own.

You are wasting peoples time with these jokes.