Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable mod_expires for browser caching

The htaccess file looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]




</IfModule>
<IfModule mod_expires.c>


# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"

# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
# CSS
ExpiresByType text/css "access plus 1 week"
# Javascript
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/html "access plus 1 day"
</IfModule>

# END WordPress

Any reason why this wouldn't enable browser caching? I am running Centos 5 and have made sure the expires module is installed.

like image 219
Atrag Avatar asked Nov 07 '22 14:11

Atrag


1 Answers

Try to use this... by file extension... change the max-age for your needs

and even use DEFLATE to compress the download size

# 1 YEAR = 29030400 || 2 DAYS = 172800 || 1 MIN = 60
# 1 WEEK = 604800
<filesMatch "\.(jpg|jpeg|png|gif|swf|xml|txt|css|js|ico|pdf|flv|html|htm)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>

#compress
<filesMatch "\.(js|css|json|html|xml)$">
SetOutputFilter DEFLATE
</filesMatch>
like image 86
shushu304 Avatar answered Nov 14 '22 21:11

shushu304