nameisbrian - 9:10 am on Jun 11, 2012 (gmt 0)
Generally, the browser reads elements top to bottom (or works that way), when it runs into the script element, it'll look at the src attribute and download that file (of course this is different when you have defer and async set on your script element).
Once the script has been downloaded and executed, this is when event handlers can be invoked. This will continue on, whether the file is cached or not. If the file has been changed, the events will still work, as the browser has not redownloaded the changes. If the user clicks away and comes back, they will be presented with whatever file was generated last.
I do not know too much about caching. To my knowledge, if the user refreshes, the same JS file will be used even if it has been changed. If they do a hard refresh, usually f5, then the files will be requested again even if they haven't been changed. When the file is cached, and the file hasn't changed, leaving and coming back to the file will have the server respond with a "304 Not Modified". This information needs to be verified, as I am just saying this off the top of my head with little research in how caching works.
The way you described what you were doing, it sounds like you are having a PHP script output data to the same file, instead of having PHP code in the file to generate the content. This can cause other issues. For example, what if multiple users are requesting a change? The file would be locked because PHP is still editing it.
To get around this, your PHP code should be in the JS file, or should be generating inline scripts in your HTML file, instead of generating a file and outputting it.
As far as my suggestion in my first post goes, I was thinking you were allowing a user to select a few static libraries. If you are, then my first post is the best option. Now, I am assuming that your JS code is dynamically changed based on user options, in which case, you wouldn't be able to easily generate a bunch of static files since there are too many changes to consider. However, generating a file that a user creates is really not a big deal. You could store the locations of the files in a database and delete them overtime.