I looked but from what I see most questions that have anything to do with this refer to an old version of Sharepoint where something is always different from what I see in SP2013.

I basically just need to add some js and a CSS file to every single page in a farm. Is there a way to do this without having to edit a Master Page?

5 Answers 5


You can do so by using Delegate Controls which is by default included in master pages. There is a delegate control on master pages called AdditionalPageHead and it allows you to add multiple controls to it.

This means you can write a SharePoint FEATURE and register your own control which adds references to the JS files.

It is described in detail at: http://blogs.msdn.com/b/kaevans/archive/2011/04/06/adding-jquery-to-every-page-in-sharepoint-with-delegate-controls.aspx

  • 2
    Thank you. This worked like a charm. However what you linked to was for SharePoint 2010. I had to change the ControlSrc attribute and add a /15/ after _controltemplates.
    – Lorenzo
    Aug 28, 2013 at 20:09

there's a way of getting JS included in all pages using Custom Actions, should work with SharePoint 2013 as well:

Edit: Sorry, here's the actual how-to on using CustomActions to reference JavaScript files: How to add custom JavaScript code to all SharePoint 2010 pages (CustomAction)

but just in case,

ScriptLink registration in SharePoint 2013 sandbox solution causes blank page

< SharePoint:ScriptLink language=”javascript” Defer=”true” runat=”server” Localizable=”true” Name=”code.js” />

That should do the trick within the masterpage! the custom javascript file Name=”code.js” would be located at:

C:\Program Files\Common files\Microsoft Shared\Web Server Extensions\15\Template\layouts\1033

to put it in a custom folder do Name=”/customFolder/code.js” which equals:

< SharePoint:ScriptLink language=”javascript” Defer=”true” runat=”server” Localizable=”true” Name=”/customFolder/code.js” />

C:\Program Files\Common files\Microsoft Shared\Web Server Extensions\15\Template\layouts\customFolder\code.js

if you set Localizable=”false” is set to false that means it will take it from a custom folder within _layouts folder, if set to true it would be mapped to 1033 (english) folder!

  • This is the 2013 way
    – Hugh Wood
    Oct 17, 2013 at 9:30
  • @HughWood The difference between this answer for 2013 and 2010 is a change of the folder 15 to 14. I'm pretty sure someone would be able to figure it out(I know I did). Otherwise this answer works. Jun 16, 2014 at 18:48

Edit: This response is how to do it in a master page. After seeing the responses you may just want to edit the master page. It seems much simpler.

Anyway, all you need to do is simply add all custom JavaScript includes after this line in the Master Page: <SharePoint:CustomJSUrl runat="server" />. You can create a delegate control but that's very painful for something so simple. My assumption is that the code above is said delegate control but if you add <script> tags after that line you'll be golden.

  • So I can basically download the sharepoint 2013 master template from the browser, edit it in my text editor to add my js script links at the bottom of the page (before the body element closes), save the document, upload it again and everything will work perfectly for the site?
    – klewis
    Jun 5, 2014 at 20:21
  • Go for it! The worst that could happen is that it wouldn't work, but I'd be shocked if it didn't. I usually load my libraries up top and then any executing code before closing the <script> tag.
    – EHorodyski
    Jun 6, 2014 at 14:17

For me, and to make my work modular, I prefer to have a JavaScript file with every page (i.e. for /Lists/Products/AllItems.aspx page I love to have Products/AllItems.js.

You can achieve this logic by using delegate control with simple Switch/case and inject Script file reference into the delegate control after checking the URL

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.