Skip to content

A platform for community discussion. Free, open, simple.

FIX: add cache breaker for fonts

Sam Saffron7b7357147e45
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