How to set caches with Apache?

Ask a question
7

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

Coin iconoffer bounty
add comment

1 Answer

6

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"
add comment

Your Answer