Skip to content

Instantly share code, notes, and snippets.

// I use Rails and my Stimulus controllers are available in application.controllers.
// This adds a listener that is triggered when the turbo:before-cache event is emitted
document.addEventListener('turbo:before-cache', function () {
application.controllers.forEach(function (controller) {
try {
if (typeof controller.disconnect === 'function') {
controller.disconnect()
}
} catch (_) {}
})