How to cache font files with Apache HTTP server

Font files are not often updated, you can cache it for a looooong time.

Here are a piece of Apache configuration that adds some cache HTTP headers when a font files is sent to a client.

# Cache configuration
<IfModule mod_expires.c>

    # Activate mod
    ExpiresActive On
    # Declare fonts content-type
    AddType application/ .eot
    AddType application/x-font-ttf .ttf
    AddType application/x-font-opentype .otf
    AddType application/x-font-woff .woff
    AddType image/svg+xml .svg
    # Set cache duration
    ExpiresByType application/x-font-woff "access plus 1 years"
    ExpiresByType application/x-font-ttf "access plus 1 years"
    ExpiresByType application/ "access plus 1 years"
    ExpiresByType application/svg+xml "access plus 1 years"
    # Append "public" to header "Cache-Control"
    <IfModule mod_headers.c>
        Header append Cache-Control "public"

You want more details about HTTP Header “Cache-Control” ?? There you go: W3C documentation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.