Grails / Chrome错误:资源解释为字体但使用MIME类型application / octet-stream传输

时间:2013-02-18 19:39:13

标签: google-chrome grails twitter-bootstrap font-awesome

如何在Chrome中设置woff字体的mime类型,就像字体真棒引导程序库一样?

2 个答案:

答案 0 :(得分:1)

通过将以下FontResourceMapper.groovy文件放入文件夹中来创建Grails custom mappergrails-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")
         }
      }

}

改编自halfbaked's solution

答案 1 :(得分:0)

在Config.groovy中:

grails.mime.types = [
    all:           '*/*',
    atom:          'application/atom+xml',
    css:           'text/css',
    ...
    woff:          'font/opentype'
]