2

I store JavaScript files that are used in all of our site collections in the layouts folder

hive: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\custom\)

I reference them in the masterpage like so:

<SharePoint:ScriptLink language="javascript" name="custom/test.js" runat="server" Localizable="false" />

I get nice caching of the file:

Unfortunately the rev hash does not get modified when I change the file test.js; I was under the impression it should very well change upon modification of the file.

Is this expected behaviour? How can I make SP deliver an updated rev hash other than restarting the application pool?

8
  • We usually do it manually in masterpage by adding v=1.1 like name="custom/test.js?v=1.1" for example Commented Apr 12, 2017 at 9:34
  • Thanks for the comment... this is what I wanted to avoid since I'd have a lot of masterpages to update :/ Commented Apr 12, 2017 at 9:37
  • Create a separate control, place all your ScriptLinks in that control and use that control in all your masterpages. That way you would only update single control. Commented Apr 12, 2017 at 9:41
  • That sounds interesting. Would you have an example? Please create an answer with workable code so that I can accept it. Commented Apr 12, 2017 at 9:48
  • Are you using Visual studio for the solution? And is it on-premises? Commented Apr 12, 2017 at 9:49

1 Answer 1

3

Follow the below steps to add a user control in 15 hive (farm solution):

  1. right click on your project, go to add and than SharePoint Mapped Folder

  2. from the new window select Template -> Control Templates and click Add

  3. You should see a ControlTemplates folder and within that a folder named on your project. Right click and click add -> New Item

  4. You should be able to see User Control & Application Page options both are only available in Farm Solutions

  5. Add a new control name it anything "CustomScriptLinks" for example. And paste all the ScriptLinks from master page to this control. Make sure that the control is using correct namespace assembly

  6. Once done, your control is ready to use.. now in your master page use this control using @Register tag
    <%@ Register TagPrefix="MyControls" Src="~/_controltemplates/15/ProjectName/CustomScriptLinks.ascx" TagName="CustomScriptLinks" %>

  7. Than add it in your Master Page inside <head> using <MyControls:CustomScriptLinks runat="server" />

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.