This article is mainly about why the use of external JS files, what is the advantage.
Why not embed JS in HTML, this is not a good analysis? Yes, so you are good at analysis, the same others? The following reasons are not embedded in HTML:
Security: as long as you look at the source code of the page, anyone can know exactly what the code does. If a malicious developer looks at the source code, it may find a security vulnerability that could be a threat to the security of the entire site or application. In addition, copyright and other intellectual property notices can be added to external documents without interrupting the flow of pages
Code Maintenance: If the JavaScript code is scattered across multiple pages, code maintenance becomes an abnormal nightmare. It is much easier to put all JavaScript files in a directory, so that when JavaScript errors occur, there is no question about where to place the code.
caching: The browser caches all externally linked JavaScript files based on specific settings, which means that if two pages use the same file, only the file needs to be downloaded once. This will speed up the download. The same piece of code on multiple pages, not only wasted, but also increased the size of the page, thus increasing the download time.
Above is the reason why to use external JS file.