Our ASP.NET MVC application contains a significant amount of JavaScript code.
To optimize the amount of unnecessary JS being loaded to the browser, we utilize the BundleConfig.cs file to create multiple bundles. On the View, we implement logic to determine:
"If the user can access Feature A, include Bundle A"
By doing this, not only does the end-user receive only the required JS, but the JS is also present only on pages where it is needed. This allows for an easy initialization of code upon page load:
$(featureA.init);
As we consider migrating to TypeScript (currently version 3.3) ...
In Visual Studio 2017, within the Project's TypeScript Build tab, there is an option to "Combine JavaScript output into file:" where a file name can be specified (which could be used for bundling).
- This results in a single site-wide JS bundle that requires delivering everything to everyone.
- The on-page-load event is no longer ideal as the JS file is present on irrelevant pages, leading to jQuery selectors in the 'init()' function not finding certain objects in the DOM because the user is not viewing the relevant page.
Is there something I am overlooking? Can TypeScript in Visual Studio 2017 meet these requirements?