Why external JS files are used

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.