Make slider js more robust.

From #3595.