What exactly does turbo-cache-control do?

I’m trying to get Turbo integrated with a WordPress theme, but I only want this to apply to the front-end. I’ve added <meta name='turbo-cache-control' content='no-cache'> to the <head> on back-end pages, but Turbo still seems to be handling those pages from what I can tell; I’d expect the browser to do a full, standard request, but instead it loads the back-end without actually reloading, and this results in various JS errors.

Am I just misunderstanding how this meta tag is supposed to work?

You’re looking for a different meta tag, I believe. If you want it to do a full reload, you need this:

<meta name="turbo-visit-control" content="reload">

This is similar to following a link like <a data-turbo="false" href="/posts">All posts</a>, i.e. disabling Turbo Drive on a page, but more consistent, since data-turbo=“false” on links will still potentially use cached versions.

What you’re doing (<meta name='turbo-cache-control' content='no-cache'>) is something different, it still uses Turbo.visit for navigation, but it discards any cached html from your last visit to the same page. I haven’t used this myself, but I think it might be useful if you had javascript that changed the DOM before leaving the page and want these changes to be gone by next visit. More details.

Although changing the attribute to <meta name="turbo-visit-control" content="reload"> should work, I would investigate if you could just load a different javascript bundle on the backend instead? I.e. not import Turbo on backend pages at all? If that’s your goal, it will also make the backend pages slightly faster since it’s better to not load a javascript module than to load it and then jumping through hoops to disable it.

It’s also possible to use <meta name="turbo-root" content="/app"> to only use Turbo on parts of the app. Although I’m not sure how this would work if you want to use it on / but not /wp-admin (the other way around should work). I haven’t tried this attribute myself, so not an expert on this.

1 Like

Thanks! That makes a lot more sense, and I was able to use the turbo-visit-control tag to get the back-end to work as expected. I’m not actually including Turbo on the back-end, but for some reason it still behaves that way until I refresh the page. With this tag, though, everything’s working much better