I needed a simple Razor ScriptManager where I can register the scripts I need, for example a datetimepicker script. But I only want to register the scripts when I'm actually showing the datetime picker.
The datetimepicker is in a PartialView. Inside the partial view, I can now use this HTML helper:
On my MasterPage, I can output the registered scripts with this helper:
This way the datetimepicker.js script is only included on the page when the PartialView is used. When the same script is registered more than once, it will only output it one time.
There is also support for CSS and you can give an optional CDN location for each registered script. Using the web.config setting UseCDNScripts the use of local or CDN scripts can be toggled.
The Simple Razor Script Manager is available on NuGet.