Need a page refresh everytime a variant changes to get the correct code to load

Thanks for the help. Could you tell me where to put the script exactly? I assume this goes in the theme.js file? sorry i’m new to shopify and just learning.