Tuesday, 29 October 2013

Reduce the loading time of website

Following are IMP Rules to Reduce the loading time of website

1 - Make Fewer HTTP Requests (means Less Ajax Call)

2 - Use a Content Delivery Network (CDN)

3 - Add an Expires Header
    http://stackoverflow.com/questions/4603076/add-expire-headers-in-php-cant-make-it-work

4 - Gzip Components
    http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

5 - Put Stylesheets at the Top (CSS Files in head tag) 

6 - Put Scripts at the Bottom (Js files in footer)

7 - Avoid CSS Expressions (e.g 100/2)

8 - Make JavaScript and CSS External (Store the Css /Js in file and include them)
    http://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-8-javascript-css-external-7205.html

9 - Reduce DNS Lookups
    http://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-9-reduce-dns-lookups-7207.html

10 - Minify JavaScript and css files (remove space, tab, indentation etc)

11 - Avoid Redirects (remove un-necessary redirect) 

12 - Remove Duplicate Scripts(Adding same javaScript / Css files two times)

13 - Configure ETags

14 - Make AJAX Cacheable

15 - Use Server side caching

16 - Use Client side caching


17 - Run time javaScript load must use cache
18- Add following code in .htaccess (Cache the JS/Image/Css & increase speed of website)

  ExpiresActive on
  ExpiresByType image/jpg "access 2 month"
  ExpiresByType image/gif "access 2 month"
  ExpiresByType image/jpeg "access 2 month"
  ExpiresByType image/png "access 2 month"
  ExpiresByType text/css "access 2 month"
  ExpiresByType application/x-javascript "access plus 2 month"
  ExpiresByType text/javascript "access plus 2 month"
  ExpiresByType application/javascript "access plus 2 month"
  ExpiresByType image/x-icon "access plus 12 month"
  ExpiresByType image/icon "access plus 12 month"
  ExpiresByType application/x-ico "access plus 12 month"
  ExpiresByType application/ico "access plus 12 month"



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


AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript


http://stackoverflow.com/questions/2537185/how-to-set-cache-for-css-js-file
http://stackoverflow.com/questions/12882081/header-expire-on-javascript-files-not-working

You can check your website speed on http://gtmetrix.com