【问题标题】:Is it possible to load webfonts through the offline storage cache manifest?是否可以通过离线存储缓存清单加载 webfonts?
【发布时间】:2011-10-25 22:47:41
【问题描述】:

我知道我可以通过 html/css 导入我的字体,但我想知道这是否是一种可行的方法。

谢谢!

【问题讨论】:

    标签: html manifest webfonts


    【解决方案1】:

    是的,如果您将字体添加到清单文件中,它们将与其余文件一起下载,然后可以离线使用。 字体需要在离线应用所在的同一台服务器上可用,因为您无法缓存不在域中的资源。例如,您无法缓存 Google Web 字体。 我一直在对此进行一些测试,看来来自 Google 的字体在 Chrome 和 Opera 上缓存得很好,only Firefox has problems。清单的“不在您的域中”限制仅适用于通过 HTTPS 提供的情况。

    您仍然需要在您的 CSS 中使用 @font-face 规则引用字体,以便它们在您的页面中使用。例如,在您的清单文件中:

    CACHE MANIFEST
    # v1
    index.html
    style.css
    GenBasR-webfont.eot
    GenBasR-webfont.woff
    GenBasR-webfont.ttf
    GenBasR-webfont.svg
    

    在 style.css 中:

    @font-face {
        font-family: 'GentiumBasicRegular';
        src: url('GenBasR-webfont.eot');
        src: url('GenBasR-webfont.eot?iefix') format('eot'),
             url('GenBasR-webfont.woff') format('woff'),
             url('GenBasR-webfont.ttf') format('truetype'),
             url('GenBasR-webfont.svg#webfontLblSsz1O') format('svg');
        font-weight: normal;
        font-style: normal;
    }
    
    body {
        font-family: 'GentiumBasicRegular';
    }
    

    Font Squirrel 获取 Gentium 文件。

    【讨论】:

    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 2017-01-04
    • 2018-09-29
    • 2020-08-18
    • 1970-01-01
    相关资源
    最近更新 更多