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!