Search code examples
ruby-on-railsfontswebfonts

How do I get fonts to download on web when the exist?


For some reason my glyphicons are not displaying. When I look at the files in the inspector, they show up red, because they are byte 0. However I can access the links successfully:

http://admin.packagezen.com/assets/glyphicons-halflings-regular.woff

Font files exist but they come in with 0 bytes

Any idea, what is happening? Is it heroku perhaps? or rails? I put the fonts in /public/assets and the file exists when i ssh into the server.


Solution

  • You can configure the rails assets pipeline to serve this for your. Do the following:

    Drop that font in (not in public/assets):

    /assets/fonts/glyphicons-halflings-regular.woff
    

    Add the font face in your application.css that uses this font/url, this will reference the finger-printed version of this:

    @font-face {
      font-family: 'Glyphicons';
      src: font-url("/assets/fonts/glyphicons-halflings-regular.woff") format("woff");
      font-weight: normal;
      font-style: normal;
    }
    

    Then feel free to use that name anywhere to reference that font. Try it out.