Several methods of html-html link JavaScript

Source: Internet
Author: User
Tags cdata script tag

Put the JavaScript file in the head

The standard approach is to put JavaScript files inside the head tag.

<head>    <scripttype="text/javascript"src="dreamdu.js"></script></head>
    • If the browser does not support JavaScript, the contents of the script tag are ignored and can be avoided <!-- ... //--> (internal references).
    • When JavaScript has any HTML entities, there is no need to use CDATA tags (because the JavaScript code is not directly in the HTML file).
    • JavaScript files must be used js as file suffixes.
Put the JavaScript file in front of the body

To prevent web pages from loading slowly, you can also put non-critical javascript at the bottom of the page, such as the following code.

        <scripttype="text/javascript"src="dreamdu.js"></script>    </body></html>

Usually JavaScript files can be loaded into any part of the Web page using the script tag, but the standard way is to load it inside the head tag.

The contents of a JavaScript file

JavaScript files can contain any JavaScript code, such as in a dreamdu.js file

document.write("www.dreamdu.com");document.write("梦之都");
Benefits of external loading of JavaScript files
    • Avoid <!-- ... //--> the use of hacker technology.
    • Avoid using CDATA.
    • Unified definition of JavaScript code, easy to view, easy to maintain.
    • Make your code more secure, and you can compress and encrypt a single JavaScript file.
    • Browsers can cache JavaScript files and reduce broadband usage (usually only one download at a time when multiple pages are using a single JavaScript file).
Considerations for external loading of JavaScript files
    • Instead of dividing JavaScript into multiple files, multiple files increase the burden on the server and increase the server's HTTP requests.
    • A JavaScript file also increases the HTTP request.
    • Why do some Web sites have a string of numbers behind their JavaScript files? Like what:
<scripttype="text/javascript"src="dreamdu.js?1217128319"></script>

Several methods of html-html link JavaScript

Related Article

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.