首页 > 解决方案 > 无法在 Angular 5 中解码下载的字体

问题描述

编辑:我可以相对清楚地说,这是我的 Spring 应用程序的一个问题。将其上传到我的测试火力库中,不会触发这样的警告。

亲爱的程序员...

相信我,当我说,我真的尝试过在其他人的问题中发布的许多其他解释。这只是一个非常奇怪的案例。

我想尝试在 Spring 后端部署我的 Angular 5 应用程序。这真的是一个看起来像这样的准系统设置......

 @SpringBootApplication
public class AngularApplication extends SpringBootServletInitializer {

    @Configuration
    @EnableConfigurationProperties({ ResourceProperties.class })
    public class WebMvcConfig implements WebMvcConfigurer {

        @Autowired
        private ResourceProperties resourceProperties = new ResourceProperties();

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {

            long cachePeriod = resourceProperties.getCache().getPeriod().getSeconds();

            final String[] staticLocations = resourceProperties.getStaticLocations();                   
            final String[] indexLocations = new String[staticLocations.length];

            registry.addResourceHandler(
                    "/**/*.css", 
                    "/**/*.js")
                    .addResourceLocations(staticLocations)
                    .setCacheControl(CacheControl.maxAge(cachePeriod, TimeUnit.SECONDS));

            registry.addResourceHandler(
                    "/**/*.html", 
                    "/**/*.json", 
                    "/**/*.bmp", 
                    "/**/*.jpeg", 
                    "/**/*.jpg", 
                    "/**/*.png",
                    "/**/*.ttf", 
                    "/**/*.svg",
                    "/**/*.eot",
                    "/**/*.woff",
                    "/**/*.woff2"
                    )
                    .addResourceLocations(staticLocations)
                    .setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS));

            registry.addResourceHandler("/**").addResourceLocations(indexLocations).resourceChain(true)
                    .addResolver(new PathResourceResolver() {
                        @Override
                        protected Resource getResource(String resourcePath, Resource location) {
                            return location.exists() && location.isReadable() ? location : null;
                        }
                    });
        }
    }
    public static void main(String[] args) {
        SpringApplication.run(AngularApplication.class, args);
    }

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(BizviewAngularApplication.class);
    }

}

我对我的应用程序进行了富有成效的构建,将它放在我的 Spring 应用程序的静态文件夹中并运行它。外观和感觉都很棒,总而言之。没有错误,我几乎可以在每个浏览器上看到我的页面。Edge,Opera,Firefox,但仅在 Chrome 浏览器中,我会弹出一个警告,当窗口重绘时会成倍增加...

在此处输入图像描述

Failed to decode downloaded fontOTS parsing error: invalid version tag。我删除了 font-awesome 并重新安装了 4.7,但这并没有帮助。奇怪的是,字体很棒的图标都很好。我可以看到它们,并且项目中没有任何遗漏。我的意思是,这是我推出的第一个应用程序,所以我可能会遗漏一些东西,但这似乎是一个奇怪的具体问题

标签: springangulartypescriptfont-awesome

解决方案


我在使用重写规则托管 IIS 8.5 时遇到了这个问题。据我了解,问题在于文件扩展名实际上被解释为.woff?v=4.7.0.

所以我最终将它添加到我的字体扩展列表中。我对 Spring 一无所知,但是从您的列表中,我认为您应该将其添加到registry.addResourceHandler

registry.addResourceHandler(
    "/**/*.html", 
    "/**/*.json", 
    "/**/*.bmp", 
    "/**/*.jpeg", 
    "/**/*.jpg", 
    "/**/*.png",
    "/**/*.ttf", 
    "/**/*.svg",
    "/**/*.eot",
    "/**/*.woff",
    "/**/*.woff?v=4.7.0",
    "/**/*.woff2"
)

推荐阅读