浏览器警告Failed to decode downloaded font和OTS parsing error: Failed to convert *** font to ***

昨晚,在做一个自己感兴趣的东西时,发现浏览器报警告,Failed to decode downloaded font以及OTS parsing error: Failed to convert *** font to ***。

但是这个问题从来没有遇到过,在网上找了一会儿答案后,发现了类似的问题回答下有网友猜测是拦截器没通过,所以我检查了shiro的拦截配置:

<property name="filterChainDefinitions">
       <value>
                /=authc
                /index=authc
                /logout=logout
                /assets/** = anon
                /css/** = anon
                /fonts/**=anon
                /img/**=anon
                /**= user
       </value>
</property>

但是这个配置理论上是没问题的,所以不是这个问题。

今天在查阅了一些资料后,发现了可能的原因:

在maven的filter解析font文件时,它破坏了font文件的二进制文件格式,导致浏览器解析出错。

解决的思路是:font文件不需要filter,因此我们需要在配置中设置一下(SpringBoot在pom.xml中写入):

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <resources>
            <!-- fonts file cannot use filter as the data structure of byte file will be changed via filter -->
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>static/fonts/**</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>static/fonts/**</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

在经如上所示的配置后,maven在编译项目时不解析font文件,浏览器就不会报警告,字体也可以正常显示。

 

posted @ 2017-12-18 10:12  Ericzya  阅读(14426)  评论(3编辑  收藏  举报