Firstly, I don’t think refreshing the product page on variant change is a solution.
I think you have to check the existing JS functions. But still if you want to use this solution use this script in theme.liquid just before tag and keep notes you have to make changes in it a/to the theme you are using.