.htaccess를 사용하여 gziped 글꼴을 제공하는 방법? (모드 Gzip 또는 deflate 없음)
문제
다음은 내가 무작위로 시도한 것들의 목록입니다.
AddHandler application/x-httpd-php .otf
AddType
default_mimetype
auto_prepend_file = "otf.php"
zlib.output_compression = On
output_handler = ob_gzhandler
header("Content-type: application/octet-stream");
서버의 모든 PHP 파일이 Zlib을 사용하여 Gzipped를 얻지 만 .oTF 확장자를 .php로 대체하는 것도 작동하지 않았습니다.
해결책
.htaccess를 사용하면 글꼴 파일이 fontfile.otf.gz
, 브라우저는이를 요청합니다 fontfile.otf
RewriteEngine On
#Check for browser's Accept-Encoding, remove it for force return gzipped one
RewriteCond "%{HTTP:Accept-Encoding}" "gzip.*deflate|deflate.*gzip"
#check file name is endswith otf
RewriteCond %{REQUEST_FILENAME} "\.(otf)$"
#check existance of .gz file name
RewriteCond %{REQUEST_FILENAME}.gz -s
#rewrite it to .otf.gz
RewriteRule ^.*$ %{REQUEST_URI}.gz [L]
#update some response header
<FilesMatch "\.otf\.gz$">
AddEncoding gzip .gz
ForceType "text/plain"
</FilesMatch>
글꼴 파일과 웹 사이트가 크로스 도메인 인 경우 Access-Control-Allow-Origin
, Firefox는로드되지 않습니다 글꼴 물체는 크로스 도메인입니다.
Gecko에서는 웹 글꼴이 동일한 도메인 제한이 적용됩니다 (Font 파일은이 제한을 완화하는 데 사용되는 경우 HTTP 액세스 컨트롤이 사용되지 않는 한 (글꼴 파일은 사용 페이지와 동일한 도메인에 있어야합니다).
Header set Access-Control-Allow-Origin *
제휴하지 않습니다 StackOverflow