Technically it’s almost impossible for HMWP to predict IDs and scan their source codes to change them so we provide Replace in HTML feature that help on those cases.
As you said it may break some plugins that acutely use those IDs or variables.
You have two way:
1) If they are in main page source code you can create a new js file in your theme directory and paste codes there and add it’s URL to header.php then remove other code by Replace in HTML
2) Use Replace in HTML and change JS/CSS source codes manually. Not usually recommended.
Unfortunately there’s no better way.