How to Improve Website Speed by Leverage Browser Caching

Si Thu Phyo
Newbiesbox
Published in
2 min readJun 20, 2016

Leverage browser caching makes your website more faster and you can set maximum age in the HTTP headers for static resources. It can reduced numbers of HTTP request so that faster page loading time and improving user experience. You need to edit HTTP headers and set expiry time on certain files. To make leverage browser caching configuration, you need to edit .htaccess file that locates in the root of your domain. But normally, .htaccess file is hidden in cPanel by default. Use third-party FTP software like as FileZilla, CuteFTP: to edit .htaccess file since these FTP software can show hidden files. If you don’t want to use third-party FTP software, make sure that “Show Hidden Files” option is checked.

Open your .htaccess file and paste the following codes.

## EXPIRES CACHING ##
<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 application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

After adding these lines of codes, save your .htaccess file. In this sample, I set expiry age by file types. You can set any expiry time and any file type. For example, if you want to add .xls format to expire time, the code will be as follow.

ExpiresByType application/xls "access 1 month"

Now, I think that you know the concept and flow of leverage browser caching and how to modify .htaccess file. Set your own expire header request according to your website type. You can set expire header age by hours, days, month and year. This method is simple and easy for a newbie. After making this step, check your website on gtmetrix and you will see the improvement of your website performance. Be enjoy with bullet speed page loading time.

Cheers… :D

--

--

Si Thu Phyo
Newbiesbox

I’m a WordPress developer and trainer of Web Development Class at Myanmar Tech Wave. Founder of newbiesbox.com and love in writing and playing Kyokushin karate.