Self-Hosted FontAwesome Icons Not Rendering on OS X Sierra - css

For the life of me, I can't get self-hosted FontAwesome icons to render in my Angular 2 application.
My Directory structure for these fonts is:
/src/assets/app/fonts/font-awesome/4.7.0/
WebPack is using /src/ as the root when serving the site locally.
To reduce http requests in my app, I have inlined the minified FontAwesome css in my index.html file, and specified the #font-face as such in index.html:
#font-face{
font-family: 'FontAwesome';
src: local('FontAwesome'),
url('/assets/app/fonts/font-awesome/4.7.0/fontawesome-webfont.eot?v=4.7.0') format('embedded-opentype'),
url('/assets/app/fonts/font-awesome/4.7.0/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'),
url('/assets/app/fonts/font-awesome/4.7.0/fontawesome-webfont.woff2?v=4.7.0') format('woff2'),
url('/assets/app/fonts/font-awesome/4.7.0/fontawesome-webfont.woff?v=4.7.0') format('woff'),
url('/assets/app/fonts/font-awesome/4.7.0/fontawesome-webfont.ttf?v=4.7.0') format('truetype'),
url('/assets/app/fonts/font-awesome/4.7.0/fontawesome-webfont.svg?v=4.7.0#FontAwesome') format('svg');
font-style: normal;
font-weight: normal;
}
As you can see, the paths to the font files are root relative, and I am able to download the individual font files via those URLs directly, so I'm pretty sure this isn't a path issue.
In Chrome on OS X, I get squares. In Safari, I don't get any icons at all. I have combed through lots of articles with lots of people experiencing various issues similar to mine, but nothing has helped so far.
Even if I supply a specific loader for fonts:
{
test: /\.(eot|svg|ttf|woff(2)?)(\?v=\d+\.\d+\.\d+)?$/,
use: ['url']
}
it still doesn't work. On Windows 8.1/10 and Linux (Ubuntu / Mint), everything works as expected. What am I doing wrong?

I ended up using the CDN-based version of Font Awesome as self-hosting wasn't working in OS X or for Cordova builds of my app.

Related

Github Pages deploy fails to load local #font-face

I have a small Next.js app that uses a local #font-face. Everything works fine in the dev environment.
The font .woff file is stored in /public/webfonts. The #font-face import is in the globals.css file:
#font-face {
font-family: 'My Font';
src: local('My Font'), local('My-Font'),
url('../public/webfonts/My-Font.woff')
format('woff');
font-weight: normal;
font-style: normal;
}
I've deployed my app using the GitHub actions next.js workflow. The CSS and images are loaded fine but the font is not.
If I try to load the font with a path starting with '/' it throws a 404 error since the base URL is my-user.github.io and not my-user.github.io/my-repo.
If I try to load the font with a relative path it throws a CORS error.
I've searched online and found various answers recommending basically opposite solutions, but nothing works for me.
Anyone with any up-to-date info on how to tweak this issue?

Rails computes wrong asset domain for fonts only, firefox can't download

For some reason the fonts are the only assets that are loaded from the http://example.com domain instead of http://www.example.com, and because of this, are not displayed in Firefox because of CORS.
this is the less file that loads the fonts:
#font-face {
font-family: 'example';
src: asset-url('example.eot?97822167');
src: asset-url('example.eot?97822167#iefix') format('embedded-opentype'),
asset-url('example.woff?97822167') format('woff'),
asset-url('example.ttf?97822167') format('truetype'),
asset-url('example.svg?97822167#example') format('svg');
font-weight: normal;
font-style: normal;
}
Firefox says:
downloadable font: download failed (font-family: "example" style:normal weight:normal stretch:normal src index:2): bad URI or cross-site access not allowed
source: http://example.com/assets/example-c93f82c639ee9474376d8df30300127a.ttf?97822167
The asset host is set to www.example.com. why is the domain wrong? how can i change this?
Thank you
Make sure your fonts are placed in either app/assets/fonts vendor/assets/fonts or lib/assets/fonts since you're using Rails 4
Make sure your assets are precompiled, i'm not sure if rails pipeline precompiles .svg .woff etc.. by default.
config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/
Edit:
Also, make sure Rails serves static assets config.serve_static_assets = true
changed
asset-url
to
asset_url
in the .less file and all was well

rails app not finding fontawesome icons on heroku

I installed a bootstrap theme and everything is working well locally. However, when I went to push to heroku, my app couldn't find the fonts. I precompiled the assets and pushed to heroku, but no icons.
So, I made my development environment like heroku with the following in development.rb:
config.assets.debug = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
now, my dev environment can't find the font files. The font files are in two locations:
app/assets/fonts/fontawesome-webfont.*
public/assets/fontawesome-webfont.*
however, I get this error:
ActionController::RoutingError (No route matches [GET] "/assets/fontawesome-webfont.svg"):
here's how they are being loaded from the precomplied css file (application-xxxxxxxxx.css):
#font-face {
font-family: 'FontAwesome';
src: url('fontawesome-webfont.eot?v=4.0.3');
src: url('fontawesome-webfont.eot?#iefix&v=4.0.3') format('embedded-opentype'), url('fontawesome-webfont.woff?v=4.0.3') format('woff'), url('fontawesome-webfont.ttf?v=4.0.3') format('truetype'), url('fontawesome-webfont.svg?v=4.0.3#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
what am I doing wrong?
The easiest fix for me was to use the CDN described on the Font Awesome "get started" page.
Delete any local copy of the stylesheet and font files, and just put this in the head:
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
(current as of 07-07-2014, see link above for most recent release)
Keep the development environment as it was. We need to precompile assets in production mode only.
Here, I hope you need to add:
Application.rb
# Enable the asset pipeline
config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/fonts"
and update:
#font-face {
font-family: 'FontAwesome';
src: url('/assets/fontawesome-webfont.eot?v=4.0.3');
src: url('/assets/fontawesome-webfont.eot?#iefix&v=4.0.3') format('embedded-opentype'),
url('/assets/fontawesome-webfont.woff?v=4.0.3') format('woff'),
url('/assets/fontawesome-webfont.ttf?v=4.0.3') format('truetype'),
url('/assets/fontawesome-webfont.svg?v=4.0.3#fontawesomeregular') format('svg');
font-weight: normal;
font-style: normal;
}
Then run rake assets:precompile and push it to heroku. May that would go well.
I tried using asset-url instead of url putting appropriate files in assets/fonts and it worked:
#font-face{
font-family: 'Font-Awesome';
src: asset-url('font-awesome.eot');
src: asset-url('font-awesome.eot?#iefix') format('embedded-opentype'),
asset-url('font-awesome.svg') format('svg'),
asset-url('font-awesome.woff') format('woff');
font-weight: normal;
font-style: normal;
}
I simply cleaned up my public/assets folder and precompiled the assets again. Pushed to heroku and et voila! It worked liked a charm. There were a lot of repetitive files and the assets weren't updated. Hence had to clean up. I tried this when none of the above methods seemed to work for me.
Note: I'm on,
Rails - 4.1.6
Ruby - 2.1.3
font-awesome-rails - 4.2.0.0
Hope it helps anybody who comes looking for the right fix!
I had the exact same issue with Rails 4.2 and Font Awesome gem 'font-awesome-rails'.
I had to use asset-path (since I'm using sass, but I presume asset-url works too) in your #font-face declaration.
Make sure that you compile for production and not development or some other environment:
RAILS_ENV=production bundle exec rake assets:precompile
Here's the resources that helped me:
http://anotheruiguy.roughdraft.io/7379570-custom-web-fonts-and-the-rails-asset-pipeline
https://github.com/concerto/concerto/issues/518 (The comment by augustf)
Perhaps you need to add.
config.assets.precompile += %w( .svg .eot .woff .ttf )
(from http://www.jaynathan.org/2013/02/using-font-awesome-with-rails-asset-pipeline/)
Do following changes
#font-face{
font-family:'FontAwesome';
src:font_url('font/fontawesome-webfont.eot?v=3.0.1');
src:font_url('font/fontawesome-webfont.eot?#iefix&v=3.0.1') format('embedded-opentype'),
font_url('font/fontawesome-webfont.woff?v=3.0.1') format('woff'),
font_url('font/fontawesome-webfont.ttf?v=3.0.1') format('truetype');
font-weight:normal;
font-style:normal
}
it work for me

Rails - path to font does work on production, but doesn't on localhost

Here's the CSS block where I load CSS fonts:
#font-face {
font-family: 'HelveticaNeueRegular';
src: url('../fonts/helveticaneue/helveticaneue-roman.eot');
src: url('../fonts/helveticaneue/helveticaneue-roman.eot?#iefix') format('embedded-opentype'),
url('../fonts/helveticaneue/helveticaneue-roman.woff') format('woff'),
url('../fonts/helveticaneue/helveticaneue-roman.ttf') format('truetype'),
url('../fonts/helveticaneue/helveticaneue-roman.svg#helvetica_neueregular') format('svg');
font-weight: normal;
font-style: normal;
}
The fonts are located in /app/assets/fonts directory.
On the localhost, when I load the page, the fonts are not loaded, but on Heroku are all fonts loaded correctly.
What is wrong?
The reason you are seeing this, is that in a production environment all the assets are compiled and put into a single folder /assets/asset-name. With that said, both css and type faces are in the same folder, and can be accessed via the relative path. In a development environment, assets are not compiled and can be accessed at /assets/asset-type/asset-name, which means that the CSS and type faces won't be in the same folder.
To overcome this obstacle, Rails has an amazing helper called asset-url.
So for your example:
#font-face {
font-family: 'HelveticaNeueRegular';
src: asset-url('helveticaneue-roman.eot');
src: asset-url('helveticaneue-roman.eot?#iefix') format('embedded-opentype'),
asset-url('helveticaneue/helveticaneue-roman.woff') format('woff'),
asset-url('helveticaneue/helveticaneue-roman.ttf') format('truetype'),
asset-url('helveticaneue/helveticaneue-roman.svg#helvetica_neueregular') format('svg');
font-weight: normal;
font-style: normal;
}
Plus, since you added a fonts folder under assets, you will need to add this to your asset path: config.assets.paths << "#{Rails.root}/app/assets/fonts" in the config/application.rb
This has to do with the way the asset pipeline works:
In development environment, all assets are serverd dynamically from /app/assets/....
In production environment, assets are compiled and moved to /public/assets/ from where a web server can pickup the now static files.
I suspect the paths in your fonts.css (accidently?) point to the files in production environment.
To solve your situation, you basically have two options:
move the font files into your /public directory (e.g. /public/fonts) and reference the files from there:
#font-face {
font-family: 'HelveticaNeueRegular';
src: url('/fonts/helveticaneue/helveticaneue-roman.eot');
src: url('/fonts/helveticaneue/helveticaneue-roman.eot?#iefix') format('embedded-opentype'),
url('/fonts/helveticaneue/helveticaneue-roman.woff') format('woff'),
url('/fonts/helveticaneue/helveticaneue-roman.ttf') format('truetype'),
url('/fonts/helveticaneue/helveticaneue-roman.svg#helvetica_neueregular') format('svg');
font-weight: normal;
font-style: normal;
}
Use Rails' Asset helpers. A good introduction can be found here.
I finally figured out this issue - into config/application.rb add following:
config.assets.paths << Rails.root.join("app", "assets", "fonts")
config.assets.precompile += %w( .svg .eot .woff .ttf )

Is it ok if I get error saying that fonts aren't loaded but they are shown on the webpage?

I used #font-face
#font-face { // body font
font-family: 'Sofia Pro Light';
src: url('../library/fonts/Sofia Pro Light/SofiaProLight.eot');
src: url('../library/fonts/Sofia Pro Light/SofiaProLight.eot?#iefix') format('embedded-opentype'),
url('../library/fonts/Sofia Pro Light/SofiaProLight.woff') format('woff'),
url('../library/fonts/Sofia Pro Light/SofiaProLight.ttf') format('truetype'),
url('../library/fonts/Sofia Pro Light/SofiaProLight.otf') format('opentype'),
url('../library/fonts/Sofia Pro Light/SofiaProLight.svg#font-name') format('svg');
font-weight: normal;
font-style: normal;
}
and here's what Chrome Dev tool gives me
Should I ignore it? cuz everything seems to work fine.
I'd open up Fiddler and see if everything really is fine or not.
I'm assuming the files really are where you say they are. And so I suspect you've run into the same thing I did. Chrome is picky about the mime type. But the error message is misleading. Basically, when you don't have the proper mime type coming from the server for WOFF files, then Chrome will failover to another font format. In this case it's going to first failover to TTF fonts. This means that two different font formats will be downloaded in Chrome. Only, it looks like you're getting an error with TTF fonts as well so Chrome is probably downloading 3 different formats in your case.
So this is worth fixing. All you need to do is configure your server to send application/x-font-woff as the MIME Type for WOFF files.
For example, in ASP.NET you'd add this to the web.config...
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
</staticContent>
</system.webServer>

Resources