There's a lot of repeated code around for grabbing the version numbers from the HTML and passing them to this function. I think instead of that you should just add them to the body attributes in the base template and have this function check if the arguments are undefined and pull them from the HTML if they are.