0

如何在 Chrome 中设置 woff 字体的 mime 类型,就像 font-awesome bootstrap 库使用的那样?

4

2 回答 2

1

通过将以下文件放入文件夹来创建Grails 自定义映射器:FontResourceMapper.groovygrails-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")
         }
      }

}

改编自半生不熟的解决方案

于 2013-08-07T04:37:05.480 回答
0

在 Config.groovy 中:

grails.mime.types = [
    all:           '*/*',
    atom:          'application/atom+xml',
    css:           'text/css',
    ...
    woff:          'font/opentype'
]
于 2013-02-18T19:39:12.773 回答