
How to enable browser caching and gzip on your browser
Enable browser caching ( This can be done by adding a few lines of code to your .htaccess file)
This will make files such as images, js, icons, css, js to only load from your server once, subsequent visits to your site will load those files directly from the cached memory of the visitors device, therefore making load time almost instant.
To enable browser caching for specific duration just add the following lines of code in your htaccess file
480 weeks
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
# 2 DAYS
<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 2 HOURS
<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
Enable gzip
gzip is a compression system that is available on almost all browsers. Enabling it can reduce your page’s total size by over 70%, therefore improving load time.
You can enable gzip by adding the code to your .htaccess file.
.htaccess
file:<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
Otherwise just add the following line of code instead.
php_value output_handler ob_gzhandler
Note: both the caching & gzip codes for htaccess can be found online as open source to be copied and paste in your htaccess file.
1 comment so far