Only loading javascript when necessary