Speed Up websites by enabling .htaccess Caching using mod_expires and mod_headers
Caching files in browser or proxy rather than requesting every time reduces the network traffic between the server, the client.
Usually not everyone has control over their own server configuration file, but sometimes they do have .htaccess file accessibility. You can do efficient caching using the Apache .htaccess file.You need to configure few lines of commands in the .htaccess file instructing the server to handle the caching of different types of files.
Enabling file caching can greatly improve your site’s performance and speed.
- How to create and use .htaccess file? Common usage and risks
- Website or Web page redirection using a .htaccess file?
- How to specify your own ErrorDocuments using .htaccess file?
- Password Protecting website Pages and Directories using .htaccess.

2 Apache modules which are included in the distribution helps in configuring the caching in .htaccess file.They are mod_expires and mod_headers.
They are not turned on by default but you can check it by using run httpd -l; command .This will list available modules.Usually your website hosting environment will have these modules enabled.
If these modules are not enabled and if you have access to the server configuration you can enable this by uncommenting the following or similar lines in the server configuration files.
-enable-module=expires and -enable-module=headers
Using Apache Module mod_expires
Apache Module mod_expires controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server response.Browser checks the headers and if cached, the document may be fetched from the cache rather than from the source until expire time has passed.
For example you can add the following in the .htaccess file
1 2 3 4 5 6 7 8 9 | # Begin Cache Control <IfModule mod_expires.c> ExpiresActive On ExpiresByType application/x-javascript A2592000 ExpiresByType text/css A2592000 ExpiresByType image/gif A604800 ExpiresByType image/png A604800 ExpiresByType image/jpeg A604800 </IfModule> |
.htaccess Time examples
1 2 3 4 5 6 7 | 300 5 Minute 3600 1 Hour 86400 1 DAY 259200 3 DAY 604800 1 WEEK 2419200 1 MONTH 29030400 12 MONTH |
Apache Module mod_headers-Static content cache headers
This module provides directives to control and modify HTTP request and response headers.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Turn on Expires and set default expires to 1 day ExpiresActive On ExpiresDefault A86400 # Set up caching on media files for 1 month <FilesMatch ".(ico|gif|jpg|png|flv|pdf|swf|mov|mp3)$"> ExpiresDefault A2419200 Header append Cache-Control "public" </FilesMatch> # Set up 1 Hour caching on commonly updated files <FilesMatch ".(xml|txt|html|js|css)$"> ExpiresDefault A3600 Header append Cache-Control "private, must-revalidate" </FilesMatch> |
Cache-control: public means the cached version can be saved by proxies and other intermediate servers.
Cache-control: private means the file is different for different users and their private browser can cache it, but not public proxies.
Cache-control: no-cache means the file should not be cached.
This was a very limited overview of a cache setup for your Apache website.Please let me know your Comments, thoughts and if I am wrong my mistakes or any additions.
-
http://www.gloopy.co.uk/ Gloopy
Join Globinch on Social Media
Follow Globinch
Popular Posts
- Turn your Windows 7 Computer Into a Personal Wi-Fi Hotspot 20 comment(s) | 26,469 view(s)
- Search Engines for File Sharing Sites : Rapidshare Search, Megaupload and More 2 comment(s) | 18,455 view(s)
- Google Translate Now supports Bengali, Gujarati, Kannada, Tamil and Telugu 2 comment(s) | 17,344 view(s)
- Best PDF OCR Tools to Convert Scanned images to Text / Word Documents 4 comment(s) | 13,625 view(s)
- Google Top Searches Today – Hot Google Search Words today 8 comment(s) | 13,497 view(s)
- Globinch Search 0 comment(s) | 10,388 view(s)
- Access Blocked sites, Unblock Restricted Websites 16 comment(s) | 9,453 view(s)
- Password Revealer – How To Reveal- Show Password Behind Asterisks? 1 comment(s) | 8,517 view(s)
- Play Angry Birds Game Free and Offline in Chrome Browser 1 comment(s) | 8,244 view(s)
- Free Online OCR Software to Convert Images Into Searchable PDF, Doc, HTML or Text 2 comment(s) | 8,083 view(s)
Recent Articles
- How to Use Wi-Fi the Secure Way
- 5 Apps to Boost Android Performance
- Building a Smarter Site Using a WordPress Platform
- Samsung Galaxy S IV Smartphone :Summary of All the Radical Innovations
- 5 Killer Tips to Increase Traffic to Your Blog
- Domain Parking to Make Genuine Money Online
- SEO Is Not Dead, But You Need to Upgrade The Process
- A Complete SEO Guide on Using Social Media for Better SERPs
- When Should You Use Geotargeting or Setting Geographic Target in Google Webmaster Tools?
- How To Optimize Your Google+ Page And Profile For Search Engines








