Setting mod_expire, mod_deflate and mod_headers in apache

With Mod_expire you can set the time a browser keep the image and when it has to renew it (Browser caching). On many websites you get a lot of .js, .swf and .jpg files you  only want to download once. The files almost never change and so the browser can keep them for a amount of time you can set.

Example 1 (apache .htaccess):
Open your .htaccess and add something like this.
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault “access plus 1 seconds”
ExpiresByType text/html “access plus 1 seconds”
ExpiresByType image/gif “access plus 2592000 seconds”
ExpiresByType image/jpeg “access plus 2592000 seconds”
ExpiresByType image/png “access plus 2592000 seconds”
ExpiresByType text/css “access plus 604800 seconds”
ExpiresByType text/javascript “access plus 216000 seconds”
ExpiresByType application/x-javascript “access plus 216000 seconds”

This code will work if apache has the module expires.

With mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.
Example 2 (apache .htaccess):
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript

With Mod_headers module you can provide directives to control and modify HTTP request and response headers. Headers can be merged, replaced or removed.

Example 3 (apache .htaccess):

<ifModule mod_headers.c>
<filesMatch “\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$”>
Header set Cache-Control “max-age=2592000, public”
<filesMatch “\\.(css)$”>
Header set Cache-Control “max-age=604800, public”
<filesMatch “\\.(js)$”>
Header set Cache-Control “max-age=216000, private”
<filesMatch “\\.(xml|txt)$”>
Header set Cache-Control “max-age=216000, public, must-revalidate”
<filesMatch “\\.(html|htm|php)$”>
Header set Cache-Control “max-age=1, private, must-revalidate”

ALL these examples can be placed in your .htaccess file. It will speed up your website and lower the number http request.

Author: rouge
Posted in: Uncategorized

Trackback from your site.

Leave a comment

You must be logged in to post a comment.