Monday, 23 April 2012

How to Increasing website performance and decrease Loading Time

Every time I entered into a new project, I am always thinking of about the speed how www.google.co.in loads,but in vain and unable to achieve it. The reason is that they had a dedicated server and the content in their page is very less. So even if it we cannot achieve that one with using a space for domain by the Domain provider but we can minimize it.So the Questions arises as:
  1. How to improve website performance ?
  2. How to speed up website ?
  3. How to compress webpages
  4. What are the methods to improve page loading speed
  5. How to optimize webpages
  6. How to make my site to process request faster.
  7. How can I achieve Rich Look Interface and so on.

To the above 1st 5 questions you need to follow some guide lines and to last two questions you need to make some thing of your coding better and  and have good and glossy look design and for other see below.

First of all minimize your CSS,JS,image files, try to avoid the re-size of images and then put the code below in your project. You will find a change in speed and performance of your site. Go to your Global.asax file and add the Code below or create a new Global.asax file( if not there ) and add the code to it.See below how to create the Global.asax file.

How to create Global.asax
Adding a Global.asax to your web project is quiet simple.
Open Visual Studio 2005 or 2008 or 2010 or 2011 beta> Create a new website > Go to the Solution Explorer > Add New Item > Global Application Class > Add.


Add the code below to Global.asax file:
 void Application_PreRequestHandlerExecute(object sender, EventArgs e)
    {
     //Create an application variable
        HttpApplication app = sender as HttpApplication;
     //<span class="IL_AD" id="IL_AD3">check</span> for null referance
        if (app == null || app.Context == null || app.Context.CurrentHandler == null)
            return;
        string acceptEncoding = app.Request.Headers["Accept-Encoding"];
        Stream prevUncompressedStream = app.Response.Filter;
     //check whether the application is eligible for compression
     if (!(app.Context.CurrentHandler is Page || app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler") ||
            app.Request["HTTP_X_MICROSOFTAJAX"] != null)
            return;
        if (acceptEncoding == null || acceptEncoding.Length == 0)
            return;
        acceptEncoding = acceptEncoding.ToLower();
        // if the application accept defalte encoding, encode it with deflate, which is the lighter one
        if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
        {
            // defalte
            app.Response.Filter = new DeflateStream(prevUncompressedStream,
                CompressionMode.Compress);
            app.Response.AppendHeader("Content-Encoding", "deflate");
        }
            //endoe with gzip
        else if (acceptEncoding.Contains("gzip"))
        {
            // gzip
            app.Response.Filter = new GZipStream(prevUncompressedStream,
                CompressionMode.Compress);
            app.Response.AppendHeader("Content-Encoding", "gzip");
        }
    }

No comments:

Post a Comment