This is the same JS as elsewhere, why don't you copy all the commonly used JS code into a separate .js file and include those in all the required templates?