1. A computer implemented method of detecting global variables in JavaScript code, and adding local variables in place of said global variables, comprising: receiving a JavaScript code containing at least one of a plurality of globally defined functions; identifying at least one of: one or more confined global variables which receive a value within a first JavaScript scope wherein said value is not referenced outside of said first JavaScript scope, and one or more repeating global variables accessed repeatedly within a second JavaScript scope; and adding local variables in place of at least one of said confined global variables and said repeating global variables.