Skip to content

Commit

Permalink
Move fonts (#9)
Browse files Browse the repository at this point in the history
Moves fonts to asset pipeline. Also adds `font-display: swap` to prevent
a "flash of invisible text" in browsers, per PageSpeed Insight's
recommendations.
  • Loading branch information
seanmack committed Sep 14, 2023
1 parent 7cf70d7 commit 9a7adb7
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
//= link_directory ../stylesheets .css
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link_directory ../fonts .woff
//= link_directory ../fonts .woff2
Binary file added app/assets/fonts/roboto-v29-latin-700.woff
Binary file not shown.
Binary file added app/assets/fonts/roboto-v29-latin-700.woff2
Binary file not shown.
Binary file added app/assets/fonts/roboto-v29-latin-900.woff
Binary file not shown.
Binary file added app/assets/fonts/roboto-v29-latin-900.woff2
Binary file not shown.
Binary file added app/assets/fonts/roboto-v29-latin-regular.woff
Binary file not shown.
Binary file added app/assets/fonts/roboto-v29-latin-regular.woff2
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,29 @@
font-style: normal;
font-weight: 400;
src: local(''),
url('/assets/fonts/roboto-v29-latin-regular.woff2') format('woff2'),
url('/assets/fonts/roboto-v29-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
url('<%= asset_path "roboto-v29-latin-regular.woff2" %>') format('woff2'),
url('<%= asset_path "roboto-v29-latin-regular.woff" %>') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
font-display: swap;
}
/* roboto-700 - latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 700;
src: local(''),
url('/assets/fonts/roboto-v29-latin-700.woff2') format('woff2'),
url('/assets/fonts/roboto-v29-latin-700.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
url('<%= asset_path "roboto-v29-latin-700.woff2" %>') format('woff2'),
url('<%= asset_path "roboto-v29-latin-700.woff" %>') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
font-display: swap;
}
/* roboto-900 - latin */
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 900;
src: local(''),
url('/assets/fonts/roboto-v29-latin-900.woff2') format('woff2'),
url('/assets/fonts/roboto-v29-latin-900.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
url('<%= asset_path "roboto-v29-latin-900.woff2" %>') format('woff2'),
url('<%= asset_path "roboto-v29-latin-900.woff" %>') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
font-display: swap;
}
body,
html {
Expand Down
5 changes: 3 additions & 2 deletions app/views/layouts/static.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
<%= tag :link, rel: 'preload', as: 'image', href: yield(:preload_image_path) %>
<% end %>
<link rel="preload" as="font" type="font/woff2" href="/assets/fonts/roboto-v29-latin-regular.woff2" crossorigin>
<link rel="preload" as="font" type="font/woff2" href="/assets/fonts/roboto-v29-latin-700.woff2" crossorigin>
<%= preload_link_tag asset_path("roboto-v29-latin-regular.woff2"), type: "font/woff2", crossorigin: "anonymous", as: "font" %>
<%= preload_link_tag asset_path("roboto-v29-latin-700.woff2"), type: "font/woff2", crossorigin: "anonymous", as: "font" %>

<!-- Preload an image - tag not rendered if preloadImg is blank to stop console errors
{% if preloadImg != '' %}
Expand Down
4 changes: 4 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.assets.debug = true
config.assets.compile = true
config.assets.check_precompiled_asset = false
end

0 comments on commit 9a7adb7

Please sign in to comment.