Caching problem when swapping between different sites?

I am maintaining 3 different Hugo based sites, with slightly different themes. I use the built-in hugo server command while developing and writing content.

Sometimes if I have been working on site A, then I change to site B, things aren’t quite right. It appears that the local server is picking up site A’s css files instead of the same named css for site B. The fault seems intermittent and usually corrects itself at some random point.

It always seems to be OK when I create the full site is the public folder, but it is a bit of a pain while I am creating content.

Is this a known problem, and is there a workaround?

Just curious - (assuming are you using localhost:1313 for all of them), are you setting your browser to not cache anything?

Also curious, are you pulling in any dynamic or “data-driven” content? For example, do you find that this eliminates the problem…

hugo server --ignoreCache

What I usually do is set a different port for each project, which ensures that the same named css files, etc, don’t get cached under localhost.

you can use the -p flag on hugo server to set the port.

1 Like

@mattstratton This is a much better solution than the one I proposed. I need to figure out where to put this in the new docs. Thanks!

I’ll mention what I was going to say in case the thread goes stale.

I’m constantly switching back and forth between sites in development. I may use the port flag if I’m running more than one at a time (though, actually, the Hugo server does this for you automatically, even without the flag), but I’ve never seen this problem on localhost:1313 when running a fresh cache. I think the original poster’s issue is with browser cache.

So, the simplest answer is to run your localhost sites in a non-cached browser tab. So, for Chrome that’s Incognito/private mode, or, better yet, in the dev tools settings you can check “Disable cache (while DevTools is open)” and just “cmd-option i” and leave it in another window, which is handy anyway. Other browsers have similar settings.

FWIW, I also use Chrome Canary as my dev browser (Firefox has a dev browser, too), so it’s pretty seamless.

I hope that’s helpful. I think there’s plenty here to answer the question.


Thanks, it looks like it probably is browser caching. I didn’t really make the connection that switching between different hugo sites would clash, but it is fairly obvious when it’s pointed out.

I will try using different ports for each project, I think that should fix it.

1 Like

I make sure to use different ports when working on localhost from site to site, but @budparr recommendation is the real solution for the caching of Hugo development. Especially when you are using a javascript compiler on js assets.

I just came across the caching issue myself. I tested a different icon font for one of my projects and then when I reverted back to the original, the icons weren’t displaying at all --ignoreCache didn’t help. Using an incognito tab solved it.