From ffb3c9987c2f820b99e8ad0ad56db8ae0324671c Mon Sep 17 00:00:00 2001 From: erdgeist Date: Tue, 14 Jul 2026 16:52:03 +0200 Subject: Extend static-asset cache-busting to the public layout mtime_busted_path only ever covered the four admin-only static files. The public layout has the identical exposure -- ccc.css, glightbox's vendored CSS/JS, and public.js are all served straight from public/ with no pipeline fingerprinting either -- just never got the same treatment. --- app/helpers/admin_helper.rb | 6 ------ app/helpers/application_helper.rb | 14 ++++++++++++++ app/views/layouts/application.html.erb | 8 ++++---- test/models/helpers/admin_helper_test.rb | 10 ---------- test/models/helpers/application_helper_test.rb | 14 ++++++++++++++ 5 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 test/models/helpers/application_helper_test.rb diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 6c3cbc6..2684fff 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -7,10 +7,4 @@ module AdminHelper link_to raw('Deutsch'), url_for(params.permit(:locale, :page_path).to_h.merge('locale' => 'de')) end end - - def mtime_busted_path(path) - file = Rails.public_path.join(path.sub(%r{\A/}, "")) - raise "Static asset not found for cache-busting: #{path} (looked for #{file})" unless File.exist?(file) - "#{path}?v=#{File.mtime(file).to_i}" - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 87aa82c..0d28661 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -15,4 +15,18 @@ module ApplicationHelper def resolve_kind_text(value) value.respond_to?(:call) ? value.call : value end + + # Cache-busts a static file living directly under public/, outside the + # asset pipeline -- used by both the admin and public layouts, since + # neither loads its static CSS/JS through Sprockets (admin_bundle.js is + # the one exception; it already gets pipeline fingerprinting for free). + # Raises rather than silently omitting the version param: a missing + # file here means the page is already broken, and failing loudly beats + # a confusing "why is the browser still showing the old version" report + # days later. + def mtime_busted_path(path) + file = Rails.public_path.join(path.sub(%r{\A/}, "")) + raise "Static asset not found for cache-busting: #{path} (looked for #{file})" unless File.exist?(file) + "#{path}?v=#{File.mtime(file).to_i}" + end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 57d12e6..d7681af 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -10,10 +10,10 @@ <%= page_title %> - - - - + + + + <%= auto_discovery_link_tag(:atom, '/rss/updates.xml', title: "ATOM") %> <%= auto_discovery_link_tag(:rss, '/rss/updates.rdf', title: "RSS") %> diff --git a/test/models/helpers/admin_helper_test.rb b/test/models/helpers/admin_helper_test.rb index 94e9861..23d9f40 100644 --- a/test/models/helpers/admin_helper_test.rb +++ b/test/models/helpers/admin_helper_test.rb @@ -1,14 +1,4 @@ require 'test_helper' class AdminHelperTest < ActionView::TestCase - test "mtime_busted_path appends the file's real mtime as a query param" do - path = "/stylesheets/admin.css" - expected_mtime = File.mtime(Rails.public_path.join("stylesheets/admin.css")).to_i - - assert_equal "#{path}?v=#{expected_mtime}", mtime_busted_path(path) - end - - test "mtime_busted_path raises clearly for a missing file rather than silently omitting the version" do - assert_raises(RuntimeError) { mtime_busted_path("/stylesheets/does_not_exist.css") } - end end diff --git a/test/models/helpers/application_helper_test.rb b/test/models/helpers/application_helper_test.rb new file mode 100644 index 0000000..56096a5 --- /dev/null +++ b/test/models/helpers/application_helper_test.rb @@ -0,0 +1,14 @@ +require 'test_helper' + +class ApplicationHelperTest < ActionView::TestCase + test "mtime_busted_path appends the file's real mtime as a query param" do + path = "/stylesheets/admin.css" + expected_mtime = File.mtime(Rails.public_path.join("stylesheets/admin.css")).to_i + + assert_equal "#{path}?v=#{expected_mtime}", mtime_busted_path(path) + end + + test "mtime_busted_path raises clearly for a missing file rather than silently omitting the version" do + assert_raises(RuntimeError) { mtime_busted_path("/stylesheets/does_not_exist.css") } + end +end -- cgit v1.3