If you need a custom function on a page, I would leave that in the page. Anything your going to reuse between pages, should be in a global library function that you can include on all pages. Try to reuse as much as your code as you can in a library function.
Try to extract as much as your code into library functions. It's easier to maintain, and reduces code duplication.