- User loads page
- Precompiled JS and CSS are included
- CSS references wrong font URL
- User loads page
- Precompiled JS and CSS are included
- CSS references right font url
- Reproduce error on local
- Run rails server on production
1. rake assets:precompile
1.
config.public_file_server.enabled = true
for Rails 5 - You should see error
- Change font family, this will use asset-url
- then application.css needs to be renamed to application.scss
- NO need to add fonts to precompile, like:
config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/
- Look for font face definition inside your css library and copy that to application.scss
- It should be something like:
@font-face {
font-family: 'my-library';
src: url('../fonts/my-library.eot?v=2.4.0');
src:
url('../fonts/my-library.eot?v=2.4.0#iefix') format('embedded-opentype'),
url('../fonts/my-library.woff2?v=2.4.0') format('woff2'),
url('../fonts/my-library.ttf?v=2.4.0') format('truetype'),
url('../fonts/my-library.woff?v=2.4.0') format('woff'),
url('../fonts/my-library.svg?v=2.4.0#my-library') format('svg');
font-weight: normal;
font-style: normal;
}
- use
asset-url
instead ofurl
- change
../fonts
or similar to a path thatasset-url
understands - to know which path
asset-url
understands, go to rails console and enterRails.application.assets.paths
- Those are the paths you can reference from, for example is that is throwing:
[
'/my/path/1',
'/my/path/2',
'/my/other/path/3',
]
And your fonts are on /my/other/path/3/my/library/fonts/
then use
asset-url('my/library/fonts/thenameofthefont.eof')
At the end you should have something like:
@font-face {
font-family: 'my-library';
src: asset-url('my-library/fonts/my-library.eot?v=2.4.0');
src:
asset-url('my-library/fonts/my-library.eot?v=2.4.0#iefix') format('embedded-opentype'),
asset-url('my-library/fonts/my-library.woff2?v=2.4.0') format('woff2'),
asset-url('my-library/fonts/my-library.ttf?v=2.4.0') format('truetype'),
asset-url('my-library/fonts/my-library.woff?v=2.4.0') format('woff'),
asset-url('my-library/fonts/my-library.svg?v=2.4.0#my-library') format('svg');
font-weight: normal;
font-style: normal;
}