optimizing javascipt redirect