Response.Write vs Batch Inline Script: ASP.NET Performance Tips

Avoid using batch inline script using <% %> inside any kind of loops in ASP.NET or MVC. I.e  combining the .net server-side  code with plain html code in a loop is not good for performance. Too much of batch inline scripts especially inside a loop will reduce the performance of the web application. It’s also not a good practice to use too much of server-side code with <% %>.

Example For batch inline script in a loop:

Batch Inline Script

Below is an example of how to avoid batch inline script in the for loop shown above:

Avoiding Batch Inline Script

 

 

 


1 thought on “Response.Write vs Batch Inline Script: ASP.NET Performance Tips”

  1. Do you have the performance counters to confirm that inline server code is slower than Response.Write() ? AFAIK, Response.Write() will use a buffer to consolidate output, so theoretically it would be faster, but to what extend ? Is it worth it ? If the’re different by order of magnitude, then we should really consider changing the way we generate HTML.

    It would be helpful to provide evidence / measurements to prove the concept. Cheers

    Reply

Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.