Factor loop-invariant terms out of the loop.  Unless this has changed recently, most browsers are not smart enough to do this sort of thing themselves.