【问题标题】:Problem with caching font in htaccess file在 htaccess 文件中缓存字体的问题
【发布时间】:2019-11-05 14:37:06
【问题描述】:

我在 .htaccess 文件中设置了这段代码,但是 woff 字体没有缓存。

<IfModule mod_expires.c>

ExpiresActive on
ExpiresDefault "access plus 1 month"
# Web fonts

AddType application/x-font-ttf ttc ttf
AddType application/x-font-woff .woff
AddType application/font-woff2 .woff2
AddType image/svg+xml .svg
AddType application/vnd.ms-fontobject eot

# Embedded OpenType (EOT)
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType font/eot "access plus 1 month"

# OpenType
ExpiresByType font/opentype "access plus 1 month"

# TrueType
ExpiresByType application/x-font-ttf "access plus 1 month"

# Web Open Font Format (WOFF) 1.0
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"

# Web Open Font Format (WOFF) 2.0
ExpiresByType application/font-woff2 "access plus 1 month"
</IfModule>

Response Header

Accept-Ranges: bytes
Content-Length: 2416
Content-Type: application/font-woff
Date: Sun, 23 Jun 2019 05:39:21 GMT
Last-Modified: Mon, 05 Nov 2018 15:58:57 GMT
Server: Apache/2.4.18 (Ubuntu)

我也尝试过不启用 ExpiresActive 和 ExpiresDefault “访问加 1 个月”,但仍然无法再次工作。有什么问题?如何缓存这种字体?其他对象,如 CSS、JS 和所有通过 Cache-Control 方法正确缓存的图像,但我仍然无法缓存 woff 字体。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    htaccess 是否已读取?在第一行添加一些乱码,然后检查服务器是否响应 500 错误。

    【讨论】:

      【解决方案2】:

      通过这段代码修复了问题:

      <filesMatch ".(jpg|jpeg|png|gif|ico|svg|ttf|eot|woff|woff2)$">
      Header set Cache-Control "max-age=31536000, public"
      </filesMatch>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-09-23
        • 2011-08-09
        • 1970-01-01
        • 1970-01-01
        • 2020-12-17
        • 2018-12-19
        • 2011-02-02
        • 1970-01-01
        相关资源
        最近更新 更多