FontAwesome - 下载的字体解码失败

15

我已经找到了这个链接:https://stackoverflow.com/search?q=Failed+to+decode+downloaded+font

但是里面的答案没有帮助我解决问题 =/

在控制台中,我发现我的页面出现了以下错误:

Failed to decode downloaded font: http://devcomlink.kunena.dev-monkeys.com/components/com_kunena/template/devcomlink/fonts/font-awesome/fontawesome-webfont.woff2
    index.php?option=com_kunena&view=category&layout=list&Itemid=129&templateStyle=9:1 Failed to decode downloaded font: http://devcomlink.kunena.dev-monkeys.com/components/com_kunena/template/devcomlink/fonts/font-awesome/fontawesome-webfont.woff
    index.php?option=com_kunena&view=category&layout=list&Itemid=129&templateStyle=9:1 Failed to decode downloaded font: http://devcomlink.kunena.dev-monkeys.com/components/com_kunena/template/devcomlink/fonts/font-awesome/fontawesome-webfont.ttf

我的页面链接:http://devcomlink.kunena.dev-monkeys.com/index.php?option=com_kunena&view=category&layout=list&Itemid=129&templateStyle=9

在Firefox和IE11中,图标完全不加载...

有人有任何想法如何解决这个问题吗?

10个回答

24

我只是在为以后的观众回答。如果你正在使用maven-war-plugin,请确保在过滤中排除.woff.ttf文件,否则maven会使文件损坏。

请注意,这是原始文本的翻译,可能存在一些纰漏或不准确,仅供参考。
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
        <webResources>
            <resource>
                <directory>${basedir}/src/main/webapp</directory>
                <targetPath />
                <filtering>true</filtering>
                <excludes>
                    <exclude>**/*.woff</exclude>
                    <exclude>**/*.woff2</exclude>
                    <exclude>**/*.ttf</exclude>
                </excludes>
            </resource>
        </webResources>
    </configuration>
</plugin>

1
这真的很有帮助。 - Caleb

15
问题不在于您的HTML或CSS代码...可能是字体文件或服务器存在问题,因为正常的字体文件应该包含代码,并且可以在像这样在浏览器中打开时下载:https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.eot?v=4.7.0。而您的文件在下载时看起来是空的,没有任何代码:http://devcomlink.kunena.dev-monkeys.com/components/com_kunena/template/devcomlink/fonts/font-awesome/fontawesome-webfont.eot?v=4.3.0。尝试替换文件...

1
谢谢!我不太明白为什么文件损坏了...但现在它可以工作了!;) - Shimakuro
我在通过npm安装ui-grid时遇到了损坏的字体文件,我通过从GitHub下载文件来替换它们。 - Mr. B.
我曾经在一个共享主机上遇到了同样的问题,一开始以为是主题的原因。但实际上问题出在WinSCP上,由于某种原因,它以TEXT模式上传字体文件而不是BINARY模式。重新以二进制模式上传文件可以解决这个问题。你可以通过比较文件大小来直观地检查这一点,在文本模式下,文件大小会小几百字节。 - dev101

8

我曾经遇到过同样的问题,最终成功解决了。希望对其他人有所帮助。

我的 .htaccess 文件非常大,包含很多 RewriteCondRewriteRule,同时也使用了以下代码来过滤某些文件夹:

RewriteRule  ^(css|functions|js|media|tpl|vendor)($|/) - [L]

在添加了字体文件夹(简称为fonts,并位于public_html/中)后,问题得到解决。
RewriteRule  ^(css|<strong>fonts</strong>|functions|js|media|tpl|vendor)($|/) - [L]

请注意,为了使其生效,这行代码应该放在您的 .htaccess 文件的顶部位置。


6
maven-war-plugin的用法类似,如果您正在使用maven-resources-plugin,则需要指定不应过滤字体文件扩展名:
<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.7</version>
    <configuration>
        <encoding>UTF-8</encoding>
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>ttf</nonFilteredFileExtension>
            <nonFilteredFileExtension>woff</nonFilteredFileExtension>
            <nonFilteredFileExtension>woff2</nonFilteredFileExtension>
        </nonFilteredFileExtensions>
    </configuration>
</plugin>

SO答案中获得解决方案。


这篇文章帮助我在springboot和maven混合使用的情况下使用ExtJS应用程序。非常感谢!我想知道如果不使用stackoverflow,如何找到类似的问题。我确实在maven-war-plugin页面上进行了交叉检查,但无法理解解决我的问题的思路。 - Dirk Schumacher
真的救了我,我的图标起死回生了!谢谢。 - xdevx32

3

就我所知,我在共享的Web服务器上遇到了这个问题。我的字体文件和包含它们的文件夹的权限设置不正确。花费了我很长时间才找出问题所在。将文件夹的权限设置为755,字体文件的权限设置为644后,现在一切都完美运行了。


1
在我的情况下,这就是我的问题。谢谢。 - JFC

3
问题不在于你的HTML或CSS代码。它必须与字体文件或服务器有关。如果你的资源文件没有问题,请使用以下代码和maven-resources-plugin。将此代码添加到pom.xml文件中。
<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>static/vendor/font-awesome/webfonts/**</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
                <includes>
                    <include>static/vendor/font-awesome/webfonts/**</include>
                </includes>
            </resource>
        </resources>
</build>

2

我来晚了,但这就是在.NET MVC上为我解决问题的方法,WebForms也适用。如果您正在使用FA或GI来装饰登录表单,则Fonts文件夹将受到限制。您可以通过在web.config中执行以下操作来提前授予权限

<location path="fonts">
    <system.web>
     <authorization>
     <allow users="*" />
     </authorization>
    </system.web>
</location>

希望这能帮助到需要的人!

0

@mujtaba-fadhel的回答应该能解决大部分问题。但是如果你正在使用git,你可能需要将字体扩展名设置为二进制,以防它被转换为文本。你需要在项目根目录下创建一个.gitattributes文件。

这是一个示例,看起来可能像这样:

*.svg text eol=lf

*.eot binary
*.ttf binary
*.woff binary

在这里了解更多相关信息


0

我可能晚到了,但有一件简单的事对我很有效。我的FileZilla文件传输设置最初是选择为“ASCII”。我在某个地方读到字体文件传输应该是二进制的。所以我把设置改成了自动,并从本地的原始字体目录再次上传字体文件。结果棒极了。希望这对于需要解决方案的人有用。谢谢。

enter image description here


0

可能有多种原因,从损坏的文件到服务器问题。我只是通过更改为fontawesome CDN链接来解决了我的问题。希望这可以帮助到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接