Why to avoid in-page <script>

When dealing with the structure of javascript in a website. Currently i try to seperate all my javascript into files, something like app.js.

Although is it better just to place scripts on the actual page they appear, with tags? and if so what are the reasons?

Related posts

Leave a Reply

2 comments

  1. The general rule of thumb is to place your script files in an external file. The Yahoo Developer site also calls for this:

    Using external files in the real world generally produces faster pages
    because the JavaScript and CSS files are cached by the browser.
    JavaScript and CSS that are inlined in HTML documents get downloaded
    every time the HTML document is requested. This reduces the number of
    HTTP requests that are needed, but increases the size of the HTML
    document. On the other hand, if the JavaScript and CSS are in external
    files cached by the browser, the size of the HTML document is reduced
    without increasing the number of HTTP requests.