How to set caches with Apache?

Ask a question+

I am trying to make your application’s performance better. I want to set caches and times for the files. How can I do it? Any suggestions? Please, if possible, provide an example. Thanks in advance.

Oliver 690
add comment

1 Answer


use a2enmod expires
ExpiresDefault "base[plus num type] [num type] ..." ExpiresByType type/encoding "base[plus num type] [num type] ..."
For seting caches use ExpiresDefault,
For seting by type use ExpiresByType
ExpiresActive on

# ExpiresByType text/html "access plus 600 seconds"

ExpiresByType text/css "access plus 30 days"
ExpiresByType text/javascript "access plus 30 days"
ExpiresByType application/javascript "access plus 30 days"
ExpiresByType application/x-javascript "access plus 30 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
ExpiresByType application/x-shockwave-flash "access plus 7 days"

# Add a far future Expires header for fonts

ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
Ian 280
add comment

Your Answer