.htaccess - 在 htaccess 文件中缓存字体的问题
问题描述
我在 .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 字体。
解决方案
通过此代码修复了问题:
<filesMatch ".(jpg|jpeg|png|gif|ico|svg|ttf|eot|woff|woff2)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
推荐阅读
- javascript - 强制 javascript 开发人员处理异常
- asp.net-mvc - Chartjs 阻止跳转到 ASP.NET MVC 5 中的一个部分
- c# - WinForms 中的 3 层表示层组织
- javascript - 我想在我的选择标签中显示选择性别作为占位符
- python - 如何在pyqtgraph中格式化Y轴显示的数字?
- xml - 在 Postgres 中将 JSONB 转换为 XML
- r - 我无法在 R 中下载 doMC 包
- java - 如何识别 postgresql 数据库中“文本”类型列中的现有换行符以在 html/jsp 页面上显示它们?
- docker - 安装 docker cifs 卷导致无法安装本地卷:权限被拒绝
- google-apps-script - 仅当条件满足时自动增加一个单元格