User Rating: 5 / 5

Star Active Star Active Star Active Star Active Star Active

When you visit for the first time a website, your browser downloads many files (images, styles, javascript and much more) we are going to call objects. In a misconfigured website, any object will be downloaded again and again each time you visit a page on that site. If you think a little, this harms your SEO ranking. Google will reward faster websites.

Since a while, the modern web browser has what it is called the cache. A web browser cache is just space on your computer where you store your latest object if those objects are requested your computer won't need to download them again, instead, it gets from the cache; local storage will be always faster than downloading from the Internet. Now think on your website, and think on all the CSS, JS and image files you are using (GIF, JPEG, PNG, WEBP, etc.); imagine all the time that can be saved when your guesses visit the second page on your website.

Apache has a very nice feature (turned off by default), that compresses the content of the page. Instead of sending the raw HTML file, it does a gzip or deflate compression and it sends a smaller file. It is faster to load a 2 kB file than a 10 kB. And as a consequence, this improves your loading time.

Again, don't forget  that Google rewards fastest websites, in other words, it improves your SEO.

In this post, I'm going to show you how to configure the .htaccess file to maximize local cache utilization.

.htaccess Configuration to improve your SEO

Here it is my configuration. Change it to fit your needs.

ExpiresActive On
ExpiresByType image/ "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"

SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/javascript text/html text/css text/plain text/xml application/x-javascript application/javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary

Header unset ETag
FileETag None

If you use another mime-type you can just added. But this combination should be enough for a generic website.


blog comments powered by Disqus