From 7b7357147e458c5c4b268a3ae9a8d40515fb526d Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 2 Sep 2020 12:17:28 +1000 Subject: [PATCH] FIX: add cache breaker for fonts This is a temporary fix since fonts may be cached without CORS A larger scale change needed. Our long term solution here is to have the SCSS compilation pipeline take care of this by introducing some SCSS var that can be consumed in the various stylesheets. We do not want to write a file on boot --- config/application.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 9b39e664bcd..76ad770d856 100644 --- a/config/application.rb +++ b/config/application.rb @@ -311,6 +311,17 @@ module Discourse # Use discourse-fonts gem to symlink fonts and generate .scss file fonts_path = File.join(config.root, 'public/fonts') + + # TODO cache breaker should be supplied from both the gem + # and the app + # we may want to keep a cache breaker in Discourse in case somehow + # Discourse changes rules for the particular asset + # + # TODO this code should move to SCSS compilation pipeline, we can have the + # font gem inject some variables into the SCSS that it can consume, instead of writing a file + # on boot + font_cache_breaker = "1" + Discourse::Utils.atomic_ln_s(DiscourseFonts.path_for_fonts, fonts_path) File.open(File.join(config.root, 'app/assets/stylesheets/common/fonts.scss'), 'w') do |file| DiscourseFonts.fonts.each do |font| @@ -326,7 +337,7 @@ module Discourse file.write <<~EOF @font-face { font-family: #{font[:name]}; - src: asset-url("/fonts/#{variant[:filename]}") format("#{variant[:format]}"); + src: asset-url("/fonts/#{variant[:filename]}?#{font_cache_breaker}") format("#{variant[:format]}"); font-weight: #{variant[:weight]}; } EOF