使用@ font-face减慢加载时间。我可以强制客户端缓存字体吗? [英] Using @font-face slows load time. Can I force the client to cache the font?
问题描述
更新:
看起来像标头请求信息是罪魁祸首。如何更改请求头的max-age属性? TIA。
Update: Looks like the header request information is the culprit. How would I change the max-age property of the request header? TIA.
您好,我在网站上使用@ font-face,文本(可能是由于每个页面加载字体)。我知道客户端必须下载字体一次才能正常显示,但每一页?
Hi, I'm using @font-face on a website and i'm experiencing delayed loading of the text (presumably due to the loading of the font every page). I understand the client has to download the font once to display properly, but every page?
有没有办法我可以强制浏览器缓存该文件?还是有另一种方法来加快字体的加载时间? (这个问题更适合在服务器故障上发布吗?)
Is there a way I can force the browser to cache that file? Or is there another alternative to speed up the font's loading time? (Is this a question more appropriate to post on Server Fault?)
感谢提前。最坏的情况下,我会忍受延迟,所以我不需要任何起飞@ font-face的答案...;)
Thanks in advance. Worst case, I'll live with the delay, so I don't need any "take off @font-face" answers... ;)
附加信息:
- 我在Safari(4)和Firefox(3.5RC1) Windows(XP和7)
- 我测试过的所有浏览器目前都设置为允许缓存(默认为开启)。
- 网址不是 是动态的,只是/fonts/font.otf
- 字体网址正确, >>
缓存控制:max-age = 0
If-Modified-Since:Wed,24 Jun 2009 03:46:28 GMT
If-None-Match:W /484d9f2-a5ac-46d10ff2ebcc0
参考资料: http://testurl.com/
User-Agent :Mozilla / 5.0(Macintosh; U; Intel Mac OS X 10_6; en-us)AppleWebKit / 530.13(KHTML,like Gecko)Version / 4.0 Safari / 530.15
Cache-Control:max-age=0
If-Modified-Since:Wed, 24 Jun 2009 03:46:28 GMT
If-None-Match:W/"484d9f2-a5ac-46d10ff2ebcc0"
Referer:http://testurl.com/
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6; en-us) AppleWebKit/530.13 (KHTML, like Gecko) Version/4.0 Safari/530.15
响应标题:
连接:Keep-Alive
日期:Thu,2009年6月25日02:21:31 GMT
Etag:484d9f2-a5ac-46d10ff2ebcc0
Keep-Alive:timeout = 10,max = 29
服务器:Apache / 2.2.11(Unix)mod_ssl / 2.2。 11 OpenSSL / 0.9.8i DAV / 2 mod_auth_passthrough / 2.1 mod_bwlimited / 1.4 FrontPage / 5.0.2.2635
Connection:Keep-Alive
Date:Thu, 25 Jun 2009 02:21:31 GMT
Etag:"484d9f2-a5ac-46d10ff2ebcc0"
Keep-Alive:timeout=10, max=29
Server:Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
推荐答案
您永远不能强制浏览器缓存某些内容,只能鼓励它。我可以想到没有理由为什么一个字体文件具有正确的过期标题不会被缓存,这使我们:
You can never force a browser to cache something, only encourage it. I can think of no reason why a font file with the correct expires headers wouldn't be cached which brings us to:
- 这是一个浏览器
- 您的浏览器已配置为不缓存任何内容(do
- 您的字体网址是动态的,因此浏览器认为每个请求都是不同的资源
- 延迟不是由字体下载造成的(您确实说您这是问题)
- It's a browser bug (you don't say which browser)
- Your cache control headers are missing or wrong
- Your browser is configured to not cache anything (do images cache?)
- Your font URL is dynamic so the browser thinks each request is for a different resource
- The font face file is actually missing or or the URL misspelt.
- The delay is NOT caused by the font download (you did say you presume this is the issue)
我想更多的信息是有序的。
I think more information is in order.
编辑:设置缓存控制是一个服务器和语言具体事情。有关Apache缓存的信息,请参阅 mod_expires 。
To set cache control is a server and language specific thing. Look at mod_expires for information on caching in Apache.
这篇关于使用@ font-face减慢加载时间。我可以强制客户端缓存字体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!