<p>I would like to know when I should include external scripts or write them inline with the html code, in terms of performance and ease of maintenance.</p>

<p>What is the general practice for this?</p>

<p>Real-world-scenario - I have several html pages that need client-side form validation. For this I use a jQuery plugin that I include on all these pages. But the question is, do I:</p>

<ul>
<li>write the bits of code that configure this script inline?</li>
<li>include all bits in one file that's share among all these html pages?</li>
<li>include each bit in a separate external file, one for each html page?</li>
</ul>

<p>Thanks.</p>

At the time this answer was originally posted (2008), the rule was simple: All script should be external. Both for maintenance and performance.
(Why performance? Because if the code is separate, it can easier be cached by browsers.)
JavaScript doesn't belong in the HTML code and if it contains special characters (such as
```
<
```
,
```
>
```
) it even creates problems.
Nowadays, web scalability has changed. Reducing the number of requests has become a valid consideration due to the latency of making multiple HTTP requests. This makes the answer more complex: in most cases, having JavaScript external is
still
recommended. But for certain cases, especially very small pieces of code, inlining them into the site’s HTML makes sense.