Call 1300 467 843

Caching with .htaccess
Minimize

OZ-KBA-8002: Caching with .htaccess

This KB will explain:
•    What is .htaccess?
•    Why would I want to use Caching with .htaccess?
•    How do I use .htaccess?

Article


Why would I want to use Caching with .htaccess?

Using Caching with .htaccess can increase the speed of your website and reduce the bandwidth being used, all by using the Viewer’s Browser and its ability to Cache Content.
 

When a page is first viewed in a browser all of the images, CSS, JS and the actual page itself is downloaded to the Browser’s Cache. This prevents the Browser from Querying the Webserver everytime a page is reloaded. With .htaccess Caching you can define how long the Viewer’s Browser should keep a copy of the already downloaded content.
 

If you have many static images it is often a good idea to set the Cache Expiry date far into the future to stop the Browser from downloading the image every time the page is reloaded.
 

More commonly updated files like the HTML, CSS and JS files should have a shorter Expiry period.
 

<Sub Heading 1>
# Header Caching
# http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html
# 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|css|js)$">
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>

<Body Text>


<Sub Heading 1>
 

<Body Text>