[Solved] Browser Error: Failed to decode downloaded font and OTS parsing error: Failed to convert *** font to ***

Last night, when I was doing something I was interested in, I found that the browser alarm failed to decode downloaded font and OTS parsing error: failed to convert * * * font to * * *.

However, I have never encountered this problem. After looking for the answer on the Internet for a while, I found a similar question. Some netizens guessed that the interceptor failed, so I checked Shiro’s interception configuration:

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

But this configuration is theoretically OK, so it’s not this problem.

After consulting some materials today, we found the possible reasons:

When Maven’s filter parses the font file, it destroys the binary file format of the font file, resulting in browser parsing errors.

The solution is: the font file does not need a filter, so we need to set it in the configuration (springboot is written in 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>

After the configuration shown above, Maven does not parse the font file when compiling the project, the browser will not give an alarm, and the font can be displayed normally.

Similar Posts: