我目前正在使用同一个代码库在许多网站上设置并行加载,但我遇到了字体未加载到样式中的问题。
这是它的设置方式:
.htaccess:
# Images / Styles / Scripts rewrites
RewriteCond %{HTTP_HOST} ^(images\.)?([^.]+) [OR]
RewriteCond %{HTTP_HOST} ^(styles\.)?([^.]+) [OR]
RewriteCond %{HTTP_HOST} ^(scripts\.)?([^.]+)
RewriteRule .* - [E=DOMAIN_SEGMENT:%2]
在头上
<link type="text/css" rel="stylesheet" href="http://styles.test.com/font-awesome/css/font-awesome.min.css">
其中 test.com
替换为当前站点的实际域。
在样式表中
@font-face {
font-family:'Aller';
src: url('/fonts/aller_rg-webfont.eot');
src: url('/fonts/aller_rg-webfont.eot?#iefix') format('embedded-opentype'),
url('/fonts/aller_rg-webfont.woff') format('woff'),
url('/fonts/aller_rg-webfont.ttf') format('truetype'),
url('/fonts/aller_rg-webfont.svg#Aller') format('svg');
font-weight: normal;font-style: normal;
}
许多站点使用相同的代码库,不可能在 CSS 中硬设置字体的域。 在并行更改之前,所有字体都可以正常加载。
正在正确加载样式表的其余部分。
谢谢
最佳答案
我发现了问题,字体试图从 styles.test.com/fonts/aller_rg-webfont.eot
加载,因此没有加载。
一个解决方案是在我的 .htaccess 文件中使用它
<FilesMatch "\.(ttf|ttc|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
关于css - 字体未以并行加载的样式加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32357346/