0

How in Chrome can you set the mime type for a woff font, as used by the font-awesome bootstrap library?

sparkyspider
  • 13,195
  • 10
  • 89
  • 133

2 Answers2

1

Create a Grails custom mapper by putting the below FontResourceMapper.groovy file into the folder: grails-app/resourceMappers/

FontResourceMapper.groovy

import org.grails.plugin.resource.mapper.MapperPhase

class FontResourceMapper {

   static phase = MapperPhase.ALTERNATEREPRESENTATION
   static defaultIncludes = ["**/*.woff"]

   def map(resource, config) {
      // Changes "application/octet-stream" to correct MIME type to avoid browser warning
      resource.requestProcessors << { req, resp ->
         resp.setHeader("Content-Type", "application/font-woff")
         }
      }

}

Adapted from halfbaked's solution.

Dem Pilafian
  • 5,625
  • 6
  • 39
  • 67
  • Any ideas why this needs to be done and why declaring a custom mapping in Config.droovy's grails.mime.types (as per my answer below) doesn't work? – sparkyspider Aug 12 '13 at 10:49
  • @Spider, I don't know, but it sure would be cleaner if the `Config.groovy` solution worked. – Dem Pilafian Dec 01 '13 at 05:21
0

In Config.groovy:

grails.mime.types = [
    all:           '*/*',
    atom:          'application/atom+xml',
    css:           'text/css',
    ...
    woff:          'font/opentype'
]
sparkyspider
  • 13,195
  • 10
  • 89
  • 133
  • It seems the type for `woff` should be `application/font-woff`, but it's still not working for us (Grails 2.2.3). See: http://stackoverflow.com/a/5142316/1553812 – Dem Pilafian Aug 06 '13 at 21:16