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.
Sign up or join Globinch on Social Media
Stay Connected
Follow globinch
Popular Posts
- Search Engines for File Sharing Sites : Rapidshare Search, Megaupload and More 6 comment(s) | 16258 view(s)
- Turn your Windows 7 Computer Into a Personal Wi-Fi Hotspot 15 comment(s) | 16117 view(s)
- Google Translate Now supports Bengali, Gujarati, Kannada, Tamil and Telugu 2 comment(s) | 15714 view(s)
- Google Top Searches Today – Hot Google Search Words today 12 comment(s) | 11559 view(s)
- Best PDF OCR Tools to Convert Scanned images to Text / Word Documents 20 comment(s) | 10154 view(s)
- Globinch Search 0 comment(s) | 8401 view(s)
- Access Blocked sites, Unblock Restricted Websites 15 comment(s) | 7310 view(s)
- Free Online OCR Software to Convert Images Into Searchable PDF, Doc, HTML or Text 3 comment(s) | 7238 view(s)
- Password Revealer – How To Reveal- Show Password Behind Asterisks? 7 comment(s) | 7180 view(s)
- Play Angry Birds Game Free and Offline in Chrome Browser 1 comment(s) | 7049 view(s)
Recent Articles
- Best Free Tools to Enlarge Images without Losing Quality
- How to Track Your Gmail Email and Schedule Gmail Mail Free?
- Google Webmaster Unnatural Links Detected Warning & Penalty
- How to Use Trial Software Version Forever Without Expire
- How to Use Folder as Drive or Convert Folder to Drive?
- Add Buttons, Message Boxes and Text Highlights in WordPress Post
- Top 20 Free WordPress Social Share Plugins
- rel=”shortlink” Short URL Indicator and Its WordPress Support
- Pagination SEO Using rel=”next” and rel=”prev” Link Attributes
- Watch Live IPL 2012 Season 5 Online on Your Computer or Mobile










Pingback: How to Test Your Website Completely - Validate HTML,CSS , RSS, ATOM,Mobile compatibility | Globinch
Pingback: Website Performance Test From Different Geographical Locations | Globinch
Pingback: Top 10 tips : Speed Up Blog and Blog Speed Test and Load Time | Globinch
Pingback: .htaccess Tutorial -A guide and .htaccess tricks and tips | Globinch
Pingback: Fiddler Proxy and HTTP Debugging Tool | Globinch
Pingback: Why Wordpress WP Super Cache Is Not Updating Index.php or Home Page? | Globinch
Pingback: Prevent Hotlinking of Image, Script, CSS etc Using .htaccess | Globinch
Pingback: 10 plus Tips to Optimize WordPress Blog and Site SEO | Globinch