Putting JavaScript into external files is one of my most common requests when doing code reviews. Here are six reasons to do it:
1. Performance due to Bundling
2. Security by obscurity due to minification – this is not real security but every little helps – if there’s a vulnerability this might help you find it before an attacker does
3. Scalability due to caching – whereas JavaScript in internal files is included in the HTML every time
4. Allows unit testing
5. Allows developers to put comments in code without exposing them to end users
6. Allows reusability across multiple pages
Pingback: jQuery Fundamentals | Zombie Code Kill