Maybe some of you already saw the message “Improve Leverage browser ” to speed up your website when you check on Google page speed. As Google starts considering site speed as a SEO parameter, webmaster can leverage browser caching to improve site speed and get better search engine rankings.

Browser Caching

If you set maximum age in the HTTP headers for static resources like images, css, javascript, pdt, swt, ..etc.. Browser will get these static resources from the local disk instead of network. So you must configure the web server to caching header and apply them to all static resources.

In the web server, you must turn on the mod_expires If you’re using godaddy hosting like me, it’s automatically turn on. Then add the following code to .htacess file

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>

Compress Components

Only Browser catching is not enough, the static resources still are heavily and slow down your website. This time, you must compress it before caching.

In the apache web server, turn on the mod_deflate and mod_gzip.

With the mod_deflate , copy the code below

<FilesMatch "\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>

With the mod_gzip

<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>

It’s all done. Now you can go back to the Google Page Speed and see the magic happens