Situation: Our team is currently in the process of migrating an ASP.NET application from traditional WebForms to Web API + Angular. The application is primarily used in regions with limited internet connectivity, where latency issues overshadow bandwidth concerns. Therefore, our main focus is on reducing the number of server requests, even if it involves pre-loading scripts or other resources that may not be immediately necessary.
The challenge: As we transition from WebForms user controls (*.ascx) to Angular directives and templates, the quantity of small HTML template files is rapidly increasing. This leads to multiple server requests for a single view, which poses a significant problem in areas with high latency.
Potential solution: I am considering utilizing T4 to consolidate all app templates into a unified file structured like this:
myApp.templates = {};
myApp.templates.myFirstDirective = "<div> ... lots of markup here ... </div>"
myApp.templates.mySecondDirective = "<table> ... more markup ... </table>"
This file would be fetched once and cached by the browser, eliminating the need for additional server requests during subsequent page loads. These templates can then be accessed by all directives without specifying a templateUrl
, simplifying the process.
Inquiry: Do you think this approach is viable? Are there any better methods or more Angular-centric ways to merge Angular templates into a single file?