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:

  1. 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


  1. 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.

  • 2
    I'd say no, it becomes a manual deployment, but it is only used where necessary. If you need to reuse it, you just link to that centrally stored JS file. Commented Jul 27, 2015 at 18:17

2 Answers 2


In server-side, you may register your custom action (and thus a ScriptLink custom action) on the list itself (see https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.usercustomactions.aspx).

I've never done that, but it seems you can do the same with JSOM: see https://msdn.microsoft.com/EN-US/library/office/jj246201.aspx and https://msdn.microsoft.com/fr-fr/library/office/jj246884.aspx for a complete sample.

  • Yes, you can register custom actions using CSOM, but lists don't support the ScriptLink location, the system just throws an exception when you try to do so.
    – Mike2500
    Commented Jul 27, 2015 at 18:28

The assumption that list-level registration isn't available is false. You can do this by specifying the list ID and a RegistrationType from one of these options: see MSDN on registration types. This question can also prove helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.