Page 48 - MSDN Magazine, October 2017
P. 48
WEB DEVELOPMENT
Speed Thrills:
Could Managed AJAX Put Your Web Apps
in the Fast Lane?
Thomas Hansen
According to several studies on the subject, two of the most important concerns when creating an AJAX Web app are speed and responsiveness. These are probably some of the reasons why some developers choose to create native apps instead of Web apps. But what if I told you there exists a way to create AJAX Web apps that are 100 times faster and more responsive than the apps you might know?
I’ve invented a way to create 100 percent pure JavaScript-based AJAX Web apps that reduce the bandwidth usage for your apps by at least 10 times, sometimes by as much as 300 times, depending on what types of tools you’re using and what you want to create. I refer to this technique as “Managed AJAX.”
Managed AJAX is to some extent inspired by the way Microsoft built the common language runtime (CLR). For instance, when
you create a C# application, the compiler creates a CLR assembly. This implies that your runtime environment for your end result is a “managed environment.” When you create a managed AJAX app, your result doesn’t compile down to anything different than a normal plain ASP.NET Web site; it becomes a managed environ- ment, where the JavaScript parts of your end results are completely abstracted away, the same way the CPU instructions are abstracted away when you have a CLR assembly.
How Does This Work?
Managed AJAX requires almost no new knowledge. If you’ve done any ASP.NET development, you can drop a new Control library into your .aspx pages, and continue your work, almost exactly as you’ve done before. You create a couple of ASP.NET controls, either in your .aspx markup, or in your C#/F#/Visual Basic .NET codebehind. Then you decorate your controls’ properties, add a couple of AJAX event handlers and you’re done!
The initial rendering creates plain-old HTML for you. But every change you make to any of your controls on the server side during an AJAX request is passed to the client as JSON. Therefore, the client can get away with a tiny JavaScript library, less than 5KB in total size, and you can create rich AJAX controls, such as TreeViews, DataGrids and TabViews, without ever having to use more than 5KB of JavaScript.
Realize that at this point, you’ve already outperformed jQuery as a standalone JavaScript file by almost one order of magnitude (jQuery version 2.1.3 after minification and zopflinication is 30KB).
This article discusses:
• The managed AJAX concept and how it can sharply reduce bandwidth requirements and yield improved performance
• How to adapt an ASP.NET Web Forms application to reference the p5.ajax.dll assembly
• Leveraging managed AJAX widgets to control HTML markup and update pages via AJAX requests and responses
Technologies discussed:
ASP.NET, Managed AJAX
44 msdn magazine