Prevent controllers to be executed during cache

At the moment all my controllers require a check like:

    connect() {
        if (document.documentElement.hasAttribute("data-turbo-preview")) return

        // Code for connect

And this also for disconnect and when using initialize.

There is a way to do this one time for all controllers, and then instead of preventing to run controllers when in cache, on opposite tell controller to run even if there is cache.


It seems like you want the code to not reinitialize on page loads/cache loads. You could use the data-turbo-permanent and a unique id to make the element persist across page loads.

I want to re-initialize but not on page cache, only on page load.