FIX: add cache breaker for fonts

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

diff --git a/config/application.rb b/config/application.rb
index 9b39e66..76ad770 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), '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]};

GitHub sha: 7b735714

1 Like

I followed up in: