Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Difference Between Inline Code and External Files in JavaScript

    JavaScript Tutorials


    Although it is possible to embed JavaScript directly into HTML files, it is generally considered good practice to include as much JavaScript within the code using external files. You have to keep in mind that there is no hard and fast rule regarding this practice; The arguments for using external files are:

    • Maintainability: JavaScript code that is scattered throughout various HTML pages turns code continuation into a problem. So it is much easier to have a directory for most or all JavaScript files so that developers can change JavaScript code free from the markup in which it's used.
    • Caching: Browsers cache are externally linked to JavaScript files based on specific settings, which designates that when two pages are using the same file, the file gets downloaded only once. This eventually leads to faster page-load times.
    • Future-proof: By taking JavaScript as external files, there is no need to use XHTML or comments. The syntax to include external files is the same for both HTML and XHTML.


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.