DEV Community

Kumar Swapnil
Kumar Swapnil

Posted on

5 2

A step towards a faster Web: Early flushing in c#.net

A simple demonstration to Early flushing in dotnet.

Flushing, Early flushing, head flushing or Progressive HTML is when the server sends the initial part of the HTML document to the client before the entire response is ready. All major browsers start parsing the partial response.If done correctly, the browser won't sit idle after requesting your page, rather, it can start process other important things in the meantime, like requesting static assets which would be used later on the site. It could give a significant perceived performance gain.
In this given example, I have used Thread.Sleep(200). This could be the time where your page does heavy database calls and other computation.

HomeController.cs

public ActionResult Index()
{

  PartialView("/Views/Shared/_HeadPart.cshtml").ExecuteResult(ControllerContext);
  Response.Flush();
  Thread.Sleep(200);
  return PartialView("/Views/Home/Index.cshtml");
}

_HeadPart.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <title>Hey - My ASP.NET Application</title>
</head>

Index.cshtml

<body>
    <div class="row">
        Hey there, How u doin'?
    </div>
</body>
</html>

Results With Early Flushing:

With Early flushing

Results Without Early Flushing

Without Early flushing

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay