АSP.NET Web Forms modernization series, Part 4: Single page applications and modern .NET
This is part 4 in a series of blog posts dedicated to ASP.NET Web Forms Мodernization. The series expands on the topics discussed in our Migration Guide: ASP.NET Web Forms to Modern ASP.NET whitepaper – a compilation of technical considerations for modernizing legacy .NET web applications, gathered from our experience at Resolute Software doing many .NET modernization projects.
Here is a list of all articles in the ASP.NET Web Forms modernization series:
- Part 1 – Data Access Layer Considerations
- Part 2 – Business Logic Layer Considerations
- Part 3 – UI Layer Considerations
- Part 4 – Single Page Application Framework Considerations (you are here!)
Coming up next (stick around!):
- Part 5 – Server Application Considerations
- Part 6 – Testing, Deployment and Operational Considerations
Intro
Single Page Applications (SPAs) are a thing. A big thing. If you’re not familiar with SPAs, they emulate a desktop application experience within a web app, providing fluid and seamless user interaction. This approach contrasts with traditional multi-page applications, which reload from the server every time a user requests a different page.
While AJAX was the first technology that allowed for dynamic content updates without a full page reload, a Single Page Application is a broader concept that includes design architecture. In a SPA, all necessary code – HTML, JavaScript, and CSS – is retrieved with a single page load, and the appropriate resources are dynamically loaded and added to the page as needed in response to user actions.
There should be little doubt that SPAs have transformed the web development landscape, and while SPAs are not in any way dependent on the use of .NET, modern .NET does offer some very attractive benefits, particularly for Microsoft stack developers.
Modern .NET
In case you’re not familiar with .NET, it is the latest iteration of Microsoft’s .NET platform. (It can get confusing. See Versions of .NET for the latest info.) An open-source, cross-platform framework, .NET is a significant redesign of the earlier .NET Framework, with a focus on modularity, performance, and cross-platform compatibility. .NET includes ASP.NET Core, a high-performance, extensible framework for building modern web applications.
Single page applications with modern .NET
SPAs got their start with JavaScript tools, and those tools are still popular and quite effective. So .NET now supports SPA templates, such as Angular and React.js, as a part of its ASP.NET Core offering. These templates provide a starting point for setting up an SPA, complete with a pre-configured environment and a simple example app.
Developing SPAs using .NET involves a combination of client-side and server-side technologies. On the client-side, frameworks manage user interactions, maintain application state, and handle routing. You can use JavaScript frameworks like Angular, React, or Vue.js, or you can use C# frameworks like Blazor if you prefer. Blazor applications work with JavaScript where necessary to take advantage of JavaScript libraries and frameworks. In addition, you can use Blazor custom elements to dynamically render Razor components from other SPA frameworks such as Angular or React.
On the server-side, .NET provides RESTful APIs that expose data and services to the client-side.In a .NET SPA, the server-side app and the client-side app are developed independently and can be hosted separately. However, during development, the .NET SPA services offer useful features like proxying requests to the client-side app, thus enabling integrated client-server debugging.
Why use modern .NET for SPAs?
Okay then. You can use .NET for SPA development, but should you?
Clearly, if you are working on a project using the .NET stack, it makes sense. But .NET brings several benefits to SPA development beyond simple convenience.
Performance
Modern .NET is comparatively lightweight compared to previous .NET versions. This does result in higher performance, which can result in faster server-side code execution and, therefore, faster response times for API calls.
Cross-platform
With .NET, developers can build and run apps on multiple platforms, including Windows, MacOS, and Linux.
Modularity and flexibility
The .NET modular design enables developers to include only the necessary packages, resulting in lighter, more efficient applications.
Strong tooling
With Visual Studio and Visual Studio Code, .NET offers strong tooling that makes coding, debugging, and testing easier. No doubt, developing SPAs on modern .NET is just easier if you’re already invested in the Microsoft stack and C#.
Community and corporate support
.NET is an open-source framework, and it enjoys good community support in addition to strong corporate support and regular updates from Microsoft.
Even though Reddit and StackOverflow host disagreements bordering on religious wars when it comes to the Microsoft stack, you can build some great SPAs using it. And if you’re already familiar with the dev environment or like coding in C#, you should really consider getting .NET for SPA development.
Why NOT to use .NET for SPAs
- Learning Curve
If you are a JavaScript master and haven’t used .NET before, ‘Why Bother’ comes to mind. With tools like Ember.js and other similar tools, you can write fantastic SPAs without ever using .NET. And realistically, you’ll need a JavaScript developer on a SPA project regardless of your .NET choice. - Dependency on JavaScript Frameworks
SPAs rely heavily on JavaScript frameworks. JavaScript is not the go-to language in .NET, and you’ll likely need or want to use C# in some .NET development. - Cost
If you need to pay licensing fees to Microsoft, those can add up. (Not that JavaScript frameworks are always free, but you should run the numbers here.)
When not to use SPAs at all
Just because I think SPAs are better than sliced bread doesn’t mean they’re right for you. If your website looks a lot like a collection of ‘About Us’ pages, I doubt you’ll benefit from SPAs.
But really, if your website doesn’t require a lot of user interaction, and you don’t push a lot of data updates, you might be just fine serving whole HTML web pages for every user interaction.
One of the biggest challenges of using SPAs is Search Engine Optimization (SEO). Because so much SPA content is generated by script, there is precious little HTML in place for an SEO bot to crawl and index. Google and Microsoft are getting better at managing this, but they’re still far from perfect. If you want help getting your SPA to index correctly with SEOs, drop us a line. We’d be happy to help.
The bottom line
If you’d like to pass on .NET for now, or if saying ‘Microsoft’ out loud three times gives you hives, you’re at no disadvantage. You’ll still create fantastic SPAs with the JavaScript tools that pioneered SPA development.
If you’re a Microsoft shop, or if you love C# in addition to JavaScript, you’ll be able to create fantastic SPAs more easily than ever with modern .NET. It’s certainly worth the upgrade from legacy .NET Frameworks.
Upgrade your Single Page Applications with modern .NET and unlock its powerful benefits. Get our migration guide today for a seamless transition and enhanced development experience.