 <p>You can try something like this: </p> <p><a href="http://www.javascriptkit.com/javatutors/externalphp.shtml" rel="nofollow">http://www.javascriptkit.com/javatutors/externalphp.shtml</a></p> <p>The external file doesn't have to be a .js extension. Alternatively, you could associate .js files as PHP files in apache (or whatever webserver you are running). Saving your JS files as .php is probably easiest but keep in mind that it won't share the same variables as the script rendering the page. </p>