Yes, and no...
Let's start with the "no" - The Joomla core devs have created a way to inject scripts, but no (API) way to remove them.
And, "Yes" , but it's complicated....
You'll need to create a Joomla system plugin to affect the removal.
If you do it any sooner than onBeforeCompileHead - you might end up with another script injecting it again.
This example just removes a script - because I'm injecting a new one elsewhere. You could modify this to remove and replace at the same time - but that's up to you to decide.
This is how I did it for a BS3 template I wrote. I really needed to ditch the BS 2.3 javascript and replace it with BS3 javascript. The plugin was written to accommodate removing multiple javascripts, although this example only shows one.
class PlgSystemRWBS3 extends JPlugin {
function onBeforeCompileHead() {
$doc = JFactory::getDocument();
$cfg = JFactory::getConfig();
$min = $cfg->get('debug', 0, 'INTEGER') ? '' : '.min';
$remove = array(
'/media/jui/js/bootstrap'.$min.'.js'
);
$this->_removeScript($doc, $remove);
}
private function _removeScript($o, $remove) {
$removed = false;
foreach($remove as $r) {
$found = preg_grep('/'.preg_quote($r,'/').'$/', array_keys($o->_scripts));
if(count($found) > 0) {
unset($o->_scripts[array_shift($found)]);
}
}
}
}