I need a custom ribbon button that calls a function in a js file in one particular library. To get access to the JS file, I could:
- Add the JS file reference via a content editor web part on the allitems page of the library. (which means the script reference will be on the page where it is needed) *see my edit below for a complication to this strategy
- Use a ScriptLink UserCustomAction. Of course, a ScriptLink action can only be applied at the site or web level, not at the list level. This means that the script reference will be rendered on every page of the site.
From a deployment perspective, the ScriptLink seems to be quite a bit more elegant. But it seems silly to reference a script on pages throughout the site that will not ever be referencing it. Or, am I dealing with a micro-optimization here?
edit: one additional complication. If there's a content editor web part on the allitems page (or any webpart, really), then the default ribbon tabs don't show up for the users unless they to click on the list web part. To get around this, edit the page in SPD and directly add the script reference to the page, and don't use a content editor part.