unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])
unset($doc->_scripts[JUri::base(true)'/path/to/file.js'])
is mostly how to do it, some scripts might add the full urlURL and some might not.
For script declaration it combines most scripts into one rather then seperatethan separate them, also the template is not the last place to execute before the page is rendered, so more could still be added to the script array. I am not 100% on this but I believe modules are rendered after the template and then inserted, components load based on the menu item so they load before. Also plugins can add more scripts afterwords.
In Summarysummary, depending on where it is added, it may not be possible in the template,template; plugins could be the only way.
UPDATE: Like I said, it cannot be done with just templates, but I found a way to get around that with a simple system plugin that can be used to allow it on any site. This is something that would be useful in the core and I might try to do a pull request to get it added, though anyone is welcome to. However its unlikely to be added "next release"
This is sort of inspired by wordpressWordPress but I was blown away when, by looking at source code I discovered it was basically completely supported in core, just the final step of defining a file in the template was missed. Such a useful functionality!
Note: I did this from memory, so it might not be 100% correct, looking into the JDispatcherJDispatcher
class might be a good idea if it does not work.
This
This can be very useful in many projects that need some simple plugin functionality specifically for that site, but making a custom plugin is way more work then it needs to be.