Font Awesome icons not showing in Chrome, a MaxCDN related Cross-Origin Resource Sharing policy issue

后端 未结 5 1526
一生所求
一生所求 2020-11-27 16:35

just noticed on several websites that the font awesome icons aren\'s showing in Google Chrome. The console shows the following error:

Font from origi

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 17:17

    The problem isn't with the CSS file, it has to do with how the font file is served. The font-awesome.min.css file has lines like

    @font-face{font-family:'FontAwesome';
    src:url('../fonts/fontawesome-webfont.eot?v=4.2.0');
    src:url('../fonts/fontawesome-webfont.eot?#iefix&v=4.2.0')
    format('embedded-opentype'),url('../fonts/fontawesome-webfont.woff?v=4.2.0') 
    format('woff'),url('../fonts/fontawesome-webfont.ttf?v=4.2.0') 
    format('truetype'),url('../fonts/fontawesome-webfont.svg?v=4.2.0#fontawesomeregular') format('svg');
    font-weight:normal;
    font-style:normal}
    

    which cause the browser to request an appropriate font file (eot, woff, ttf or svg) from the same server as the CSS file. This is logical and correct.

    However, when the browser requests that font file from cdn.keywest.life, it reads the headers for a Access-Control-Allow-Origin header and doesn't find one so it gives that error message. (This seems like a browser bug to me because it's coming from the same server as the CSS file).

    Instead, when you use maxcdn.bootstrapcdn.com the response includes the Access-Control-Allow-Origin:* header and the browser accepts this font file. If your cdn server included this header then it would work too.

    If you have an Apache server, see this answer: Font-awesome not properly displaying on Firefox / how to vend via CDN?

提交回复
热议问题