Thursday, September 30, 2010

ASP.NET Optimazation Tips

One question that asked by most programmers' is how to optimize their code.How to improve the performance of their overall project.I am gonna discuss the optimization issues with various languages one by one starting from asp.net.


There are some points that will help you to improve the overall performance of your asp.net coding.


  • Page.IsPostback - Page.IsPostback  gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a post back. Rather than loading all the components each time page rendered, you can use this method to load only desirable components .So use Page.IsPostback to avoid unnecessary processing on a round trip.

  • Cache Data: As I have already told you in my previous post, the client side caching is a way to cache the images and data on the client side browser or computer. Using caching helps improve the performance by reducing the overall load on the server. This is because the resources that do not change frequently are cached and are not requested by the client again and again.CACHE data and page output whenever possible.

  • View State: ASP.NET view state, is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks. Turn OFF ViewState if not being used. Ihe ViewState is configured at three levels which results in slow performance of the application,when it is Turned ON.Refer http://msdn.microsoft.com/en-us/library/ms972976.aspx for more detail about view state.

  • Session: Minimize the amount and complexity of data stored in a session state.
    The larger and complex the data is ,the higher the cost of serializing or deserializing of data.Disable the Session when it is not using.This can be done at the application level in the "Machine.Config" file or at a page level.

  • SERVER.TRANSFER: Use SERVER.TRANSFER rather than Response.Redirect, if the WebPage is present in the same application. This makes the communication faster.


  • Debug:  Disable DEBUG mode before deploying the application.

  • PRE-BATCH" compilation: Do a “PRE-BATCH" compilation.
    To achieve this, request a page from the site. Avoid making changes to pages or assemblies that are there in the bin directory of the application. A changed page will only recompile the page. Any change to the bin directory will result in recompile of the entire application.

  • Use TRACE : Use ASP.NET TRACE feature for efficient debugging instead of RESPONSE.WRITE.

  •   Server Controls : Use Server Controls in appropriate circumstances. Since, they are expensive because they are server resources even though are they are very easy to implement.


  • Release Resources: Release the native resources as soon as the usage is over.This will reduce performance issues, since by nature GC release them at a later point.This results in appropriate utilization of resources by the other Requests.

IN-PROC option will provide better performance.
SQL SERVER option provides more reliability

Hope this points will help you.

Tuesday, September 28, 2010

Asp.net and Javascript- Useful tips -2

More on asp.net and Javascript
  • Try n keep all js external.
  • Don’t assign methods in html “<a href=’doSomething’…”. Instead, render clean html and bind events to it using jquery (or any library) “selectors” and “for/each” methods. Alternatively you may also render a javascript array of “ids” to bind the function to.
  • Use JSON Serialization. Avoid manually constructing javascript arrays/objects using StringBuilder in code behind as it is tedious and unnecessary effort.
  • Lazy load contents. Reduce page load by lazy loading extra static content. Extra content can be the html which is “displayed-none” by default on your pages.
  • Put Js calls in the end. Move all “<script src=….>” to the end of your html –right before ending body tag. Even better if you can lazy load your scripts to reduce initial page load.

Asp.net and Javascript- Useful tips

Asp.NET & Javascript –Combo Tips!

Hope you all love the pretty work we do with javascript and Asp.NET together. Here are few points to always keep in mind while using the combo:
  • Use JavaScript libraries. They definitely make your work easy!
  • Always use “ServerControl.ClientID” property to read client IDs of server controls. Never hardcode IDs. Some of us have already faced the resulting issues…so better be safe!
    If you need to use the client ID in separate javascript files, you may pass client IDs as an object from the aspx page .
    Ex:  var options   = {txtNameClientID:  <%= txtName.ClientID %>};

    You can read the above “options” in your js file as:
    Ex: $(‘#’ + options.txtNameClientID);
  • Use short names for “ContentPlaceHolders”. You can save hundreds of bytes simply by giving short names to your ContentPlaceHolders. Consider that:
    1. Asp.NET prefixes contentplaceholder’s ID to all the controls kept inside it.
    2. The new IDs are copied to all javascripts and postback events on the page.
  • Use ‘$’ method. Prefer to use “$” method provided by various javascript libraries or create a little “$F” method for yourself.  ‘$’ is far more powerfull with its selectors than “document.getElementById” and it saves bytes too.
  • Store objects returned by “$” or “document.getElementById” into a “var”. Avoid tracing the document again-n-again for finding the same element.
  • Use objects in javascript.  :)
  • Use short prefixes. Ever thought we can keep all our prefixes to just “t” instead of “txt”, “l” instead of “lbl”, “d” instead of “div”?  Try keeping the prefix length of to a minimum.
Good luck & try to follow these steps.If you have any doubt,hit me back via comments.

Tips for creating SEO Friendly websites-2

  • 3 click access to any page of your website. Make sure that any page that you wish to be indexed by the search engines should be accessible from the home page in no more than 3 clicks.
  • Avoid Redirections with javascript or the server side language: Don’t make your website in such a way that clicking on a link causes the redirection using javascript or some server side language. Use href of anchor tag for redirection. Any programmatic redirection will cause the search bot not to index that particular page as it does not execute any of those statements.
  • Use Sitemaps: Sitemaps are simple text or xml files that list all the URLs one per line. You should always create at least one sitemap for your website. Your sitemap should list all the URLs that search engines should index. Some search engines including Google also give you flexibility to submit your sitemap to them for indexing purposes.
  • Incoming & Outgoing Links: The results shown by a search engine depend on various factors such as number of keywords, page relevancy, page rank etc. Generally these factors are calculated by how many other websites point to your website and vice versa. Therefore put your website link in as many different websites as you can. An easy way could be to use social networking websites and link sharing facilities.
  • Choose a good webhosting service: Be sure to choose a good webhosting company for your website. The company’s hosting server should provide a fair up time. A large downtime may cause a search engine return empty handed from your website because of no response. Although the search engine will check again during its periodic cycle, that will delay the indexing of your website.
Good luck and happy development time.

Tips for creating SEO Friendly websites

If you are the owner of a website or if you have decided to design one for your company or personal use, a question must have danced in your mind “How can I bring my website quickly to the search engines like Google and Bing”. After all what is the use of a website, if people can’t find it. Although most search engines provide webmaster tools to submit your website for indexing, there is a possibility that it will never be listed in your favorite search engine results. The reasons being poor website design from the search engine’s point of view. Yep Design matters a lot ;) .
In this article I will tell you how you can fine tune your website by following some simple guidelines to bring it up in the search engine results. Although it might not be possible for you to follow all points for your website, using more of them can help you to achieve your goal.
  • Use keywords in the title tag: Use the keywords that most likely describe your website or your company or your information in the title tag of your page. Most search engines including Google index pages based on the title tag.
  • Avoid full flash website: A website that is completely designed using flash is susceptible to be listed in the search engine results in short time. This is because the contents of the flash can’t be read or indexed by search engines. Less words from your site means less chances of it being at top.
  • Use text instead of images: Many people tend to use images which contain text. As search engines can’t read text from these images, these words are not indexed. It is therefore a better idea to use the text directly instead of images.
  • Avoid javascript computation. : A search engine bot does not execute the javascript on your page at the time of indexing. Therefore you should not place the text content by performing javascript computation as it will never be included in the search engine index.
  • Avoid iframes or frames: An iframe causes the search engine bot to individually load a single page. Therefore if you use iframes inside a page, the content of that iframe might be indexed separately as a page and could be separately shown in the search engine results, a thing that you will not want.
  • URL Rewriting: URL rewriting is a mechanism to convert the existing URLs to your pages to more user and search engine friendly URLs. URL rewriting helps search engines to properly index certain pages and refer them with those URLs. This technique is specifically useful if your website is a content management system or blog having parameterized URLs.
Hope these points help you to popularize your website among search engines. Hope to get your honest feedback.
Thanks & Good Luck

How to improve your website performance-2

 More on improving your website performance.

  • Use Ajax: Make use of Ajax(Asynchronous javascript with XML) within your website. Ajax causes the client to request data from the server asynchronously using XMLHttpRequest object instead of HttpRequest. This helps in only refreshing relevant page portion instead of redrawing the whole page. The disadvantage of relying on this is that browsers allow to disable execution of javascript in which case you require to have full page loading.
  • Avoid full flash website: A website that is fully created in flash takes some time to load completely and people visiting any website don’t like to wait. Therefore try to optimize the flash components to minimize the size or if possible avoiding them totally.
  • Use client side java script validations: Try to validate the data at the client side itself using javascript instead of relying totally on server side validations. Although you should always use server side validations, including client side validations prevents the invalid data to postback to server for mere validation. e.g. if you want to check if the user has filled the first name field in a contact form, javascript checking would be nice before form is submitted to server for same check. This reduces the server load for performing validations.
  • Use scripts at the end of page: The javascripts that you use in your pages should be included at the end of the page instead of beginning. This is because the loading of page offers in sequential manner from top to bottom. A script loading at the start reduces the overall performance of the webpage and produces delay while drawing the visual items on the page.
  • Avoid inline scripts and styles. Use external files : Most browsers cache the included javascript and css files. Therefore try to include the javascript and css styles as separate files using script tag and link tags respectively instead of using styles and scripts inline. Inline styles and scripts are loaded every time a  request is made thus reducing the overall performance.
  • Avoid blank image tags: Remove any image tags that have blank src attribute.This is because for each such image tag a separate http request is sent. This degrades the overall performance. Removing these tags can improve performance of the website which has thousands or more visits per day.
  • Minify your documents: Minifying your javascripts and css styles can help reduce the overall file sizes required for transfer from web server to client. It is a process of removing unneeded characters such as new line characters, white spaces etc. from these files and sometimes obfuscating the javascript code to reduce the file size for optimal performance. e.g.  A style such as
.classname
{
background-image:url(images/a.png);
color:white;
border:solid 1px black;
}
after minification becomes

.classname{ background-image:url(images/a.png);color:white;border:solid 1px black;}

A website using thousands of styles can save lot of bytes using this process. There are many tools available for minifying your javascript and css styles. Some free tools are JsMin , YUI Compressor Minify for php. and
Most points if not all when implemented can result in faster response times to the users of the websites thus improving the performance of your web application.
Good luck and have a happy web development

How to improve your website performance-1

A common question in the minds of webmasters or website administrators, web developers and quality assurance people is that how can we improve the performance of a website? Many factors affect the performance such as server hardware, processing power, data transmission speed and many more. One such factor is the way website has been designed. A properly designed website should produce good results in terms of performance. Following certain basic things that I have observed, the performance of the website can be drastically improved without much compromising with the functionality. Let me tell you those things one by one.
  1. Use optimized images: The images used in websites should be as small in size as possible. Less bytes mean less loading times. Depending upon the type of colors the image contains, proper image formats should be used. e.g. if the image contains solid colors or less detailed contents .png or .gif formats must be considered. For images with real world or nature images, jpg file format should be chosen for optimal performance.
  2. Use css sprites and less number of javascripts and css files: The number of http requests that is made from client to server is directly propotional to the number of files that are requested. Thus more images mean more http requests. This causes more bandwidth usage and increases load on the server. CSS sprites are special images created by merging all the images together into one image. The background-image and background-position property of css styles can be used to properly position the images on webpage. There are many websites that offer you to merge the images automatically and generate CSS for those files.  Similarly instead of having too many javascripts and css files, try to merge them all in single files so as to reduce the overall http requests.
  3. Precompile if possible : Although not possible with every web technology, technologies like ASP.NET offer flexibility to precompile the website code into dlls. This reduces the load on the server to compile the website. Although the server compiles these files once, this can give a bit of delay when first request is made for the website. Precompilation will help to reduce that delay.
  4. Use caching: The client side caching is a way to cache the images and data on the client side browser or computer. Using caching helps improve the performance by reducing the overall load on the server. This is because the resources that do not change frequently are cached and are not requested by the client again and again.

Monday, September 27, 2010

Friends!! Welcome to best programming skill

Hey friends,
I have decided to write this blog to spread my views about best programming methods in various languages.First I want to tell you that this blog will not gonna be tutorial about any programming language.Instead, based on my 10 years of experience of  programming,I am gonna tell you the best methods of programming.We will try to explore as many programming languages and will suggest you, how to maximize your programming potential.We will always try to explain this concepts in detail with use of images if required.If you have any suggestions or question, you are always welcome.