skip head and foot js when empty, backport 35230

closes universityofglasgow/issues#28