As a webmaster, one of the biggest worries of mine as far as my blog is concerned is, without any doubt, its performance, namely the ability to be downloaded in any browser in almost no time (yes, I am a bit ambitious!). As a matter of fact, the more your website is accessible the more people will be able to see it, above all those ones who have a slow Internet connection such as dial-up or ISDN connection (and believe me, there are a lot of them, more than you think!). There are a lot of techniques and open source, freeware software that can help you to achieve this result, just browse my Webmaster section to find out more. Anyway, what I didn’t know till yesterday, was that I could get amazing results just by using some nice piece of code to copy-and-paste directly in the .htaccess file located under the public_html folder.
The techniques I am going to write about involve the caching of your blog. But what does it mean? Basically, when a visitor reads a page in your blog, his browser caches its content in your server. Every time the visitor uses the cache, his browser will send a “301″ which is nothing else than a redirecting instruction to verify if that page has been changed. As you can well imagine, this is quite time and resource consuming, both for your readers and your server. That’s why we can instruct the browser to cache the page for a longer period of time, above all for those files such as: images, MP3, javascript etc. which will to stay the same for a certain period of time.
The code below needs mod_headers enabled in your server. If you don’t know if it is enabled or not, just ask your server provider. Here is the code to copy-and-paste in your .htaccess file.
# 1 YEAR
<FilesMatch “\.(ico|pdf|flv)$”>
Header set Cache-Control “max-age=29030400, public”
</FilesMatch>
# 1 WEEK
<FilesMatch “\.(jpg|jpeg|png|gif|swf)$”>
Header set Cache-Control “max-age=604800, public”
</FilesMatch>
# 2 DAYS
<FilesMatch “\.(xml|txt|css|js)$”>
Header set Cache-Control “max-age=172800, proxy-revalidate”
</FilesMatch>
# 1 MIN
<FilesMatch “\.(html|htm|php)$”>
Header set Cache-Control “max-age=60, private, proxy-revalidate”
</FilesMatch>
This second code uses mod_expires + mod_headers to work, which have to be enabled in your server.
# Turn on Expires and set default to 0
ExpiresActive On
ExpiresDefault A0
# Set up caching on media files for 1 year (forever?)
<FilesMatch “\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$”>
ExpiresDefault A29030400
Header append Cache-Control “public”
</FilesMatch>
# Set up caching on media files for 1 week
<FilesMatch “\.(gif|jpg|jpeg|png|swf)$”>
ExpiresDefault A604800
Header append Cache-Control “public”
</FilesMatch>
# Set up 2 Hour caching on commonly updated files
<FilesMatch “\.(xml|txt|html|js|css)$”>
ExpiresDefault A7200
Header append Cache-Control “proxy-revalidate”
</FilesMatch>
# Force no caching for dynamic files
<FilesMatch “\.(php|cgi|pl|htm)$”>
ExpiresActive Off
Header set Cache-Control “private, no-cache, no-store, proxy-revalidate, no-transform”
Header set Pragma “no-cache”
</FilesMatch>
Try both code and find out which one works better in your server!
Source: www.askapache.com
Tags: trick, Web Talk
Related ArticlesLatest Articles
- How to Automatically Login (Access) to Windows 8
- How to See and Read Unread, Archived and Sent Messages on Facebook
- Switch to the New Facebook Profile Layout (Timeline)
- How to Discover and Recover All Stored Passwords in your Windows Computer
Leave a Comment
Web Talk is best viewed in Firefox.
Comments
How to change language in Windows 7: i thought upon installation of Windows they warn you that you can not change the...
Can I Turn on Facebook Chat Auto Reply?: Thanks for explaining, otherwise it would have been a good option, but there are...
How to fix “Windows Explorer has stopped working” in Windows 7: simple remember if you download some new app....
How to Fix uTorrent not Working on Windows 7: desai .. first exit from process .. then try to uninstall
Use online Virtual Windows Operating System directly on your browser: a
Download 64-bit Windows 7 Build 7077 DVD ISO leaked version: hai ptoravo a disinstallare msn con l’applicazione...
Right click on shortcuts icons don’t show “open file location” in Vista: The sorhensect provided above...
Uninstall and Remove AVG Security Search Toolbar and AVG Secure Search: google jobb
Microsoft launches innovative translate widget for blogs: Definitely! It’s rlelay weird at first but...
Small, Hilarious List of Funny Google Translate Tricks: Try this: men are men and men do the cooking, translate to Dutch,...