From 7a467f356798f489978b74dd5ce1cd06cbd4ca91 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Thu, 25 Jun 2026 20:26:17 +0200 Subject: [PATCH] fix: only load Plausible analytics in production The Plausible script at /js/script.js is proxied through nginx in production (bypasses adblockers), but doesn't exist in development, causing a 404 on every page load. --- app/views/layouts/application.html.haml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 1191fa0a8..e46c5e687 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -30,11 +30,12 @@ = csrf_meta_tags = csp_meta_tag - - %script{ async: true, src: '/js/script.js' } - %script - window.plausible = window.plausible || function() { (plausible.q = plausible.q || []).push(arguments) }, plausible.init = plausible.init || function(i) { plausible.o = i || {} }; - plausible.init({ endpoint: '/api/event' }) + - if Rails.env.production? + + %script{ async: true, src: '/js/script.js' } + %script + window.plausible = window.plausible || function() { (plausible.q = plausible.q || []).push(arguments) }, plausible.init = plausible.init || function(i) { plausible.o = i || {} }; + plausible.init({ endpoint: '/api/event' }) %body.no-js{ 'class': "#{params[:controller]}-#{params[:action]}", 'data-bs-no-jquery': 'true' } #top