How to structure jquery code for a big website?

How to structure jquery code for a big website?

Hello;

In a website with 100+ pages, let's say each page has its own class, id and jquery needed to function.

I believe all javascripts shoulb be added in head like
<script src="/docs/js/jquery-ui-1.8.10.custom.js"></script>
Now how do we assign each piece of jquery to each page that requires it? For example if page A uses functions A,B, and C, and page B doesnt, how do we include them ONLY in page A without getting the site messy?

Thanks