Here is my attempt at being clever regarding this…
I actually do the following for CSS, JS, breadcrumbs, and anything else where it applies.
First, I create an includes folder that handles anything global. All of the JS that applies globally would be put into template(s) with a naming convention of .js_jquery, .js_swfobject, et cetera. For my master css template, .css_global. My HTML fragments are called .html_css, .html_masthead, .html_footer, et cetera. There is one HTML fragment for JS called .html_js which calls in the javascript.
Example:
{embed="includes/.js_global"}
{embed="{segment_1}/.js_local"}
Next, I create a template in my template group and name it “.js_local”. All of the JS that applies to this group is within this JS file.
Finally, I embed {embed="includes/.html_js"} in all of my templates. This keeps all of the JS nice and tidy between the head tags. This allows me to forget about the inclusion of specific Javascript(s) in individual templates moving forward. With this structure, I can add/delete/modify JS by heading to the .js_local or .js_global templates.
note: If JS applies to two or more template groups, I typically place it in the .js_global file with or without conditionals. Inside the local file, I use conditionals if I want the JS to apply to only one template.
another note: For JS, I use embeds in my includes/.html_js template, but for CSS I use <link rel=“stylesheet” type=“text/css” media=“all” href=”{stylesheet={segment_1}/.css_local}” /> in place of the embeds.
This may seem confusing or extraneous at first, but in my mind, it breaks everything up in manageable pieces that follows the template_group/template structure of EE. I typically avoid embeding other embeds, but I’ve noticed no penalty for this. I’d love to hear from Derek or someone within EE that could actually confirm this. This idea was born out of Derek’s Behind The Curtains II article.