3

I'd like to use the SPUtility.MakeBrowserCacheSafeLayoutsUrl method in my published master page (used in a publishing site) in order to force SharePoint to stop caching my JavaScript and CSS files.

If I was working with a traditional .aspx page, this would suffice:

 <script type="text/jscript" src="<%=Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl("projectName/scripts/plugins/tapes_report_definition.js", false)%>" ></script>

But being a published Master Page, the tagging concept is a bit different. For example, this is what a JavaScript reference looks like:

<!--MS:<SharePoint:ScriptLink name="sharing.js" OnDemand="true" runat="server" Localizable="false">-->
<!--ME:</SharePoint:ScriptLink>-->

So I've been trying various ways to include that inline call to the cache method; here's what I've tried:

Simple script tag with inline code

<script src="<%=Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl("IntrinsiQ.UserPortal.SharePoint/scripts/portal-main.js", false)%>"></script>

Result: '<', hexadecimal value 0x3C, is an invalid attribute character

Script tag surrounded in SharePoint MS/ME tags

<!--MS:<script src="<%= Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl("IntrinsiQ.UserPortal.SharePoint/scripts/portal-mainx.js", false) %>">-->
<!--ME:</script>-->

Result: Invalid SharePoint markup

Script tag surrounded in SharePoint MS/ME tags with Encoding

    <!--MS:<script src="&#60;%= Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl("IntrinsiQ.UserPortal.SharePoint/scripts/portal-mainx.js", false) %&#62;">-->
    <!--ME:</script>-->

Result: Invalid SharePoint markup

ScriptLink tag

<!--MS:<SharePoint:ScriptLink name="<%=Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl("IntrinsiQ.UserPortal.SharePoint/scripts/portal-main.js", false)%>" runat="server">-->
<!--ME:</SharePoint:ScriptLink>-->

Result: Invalid SharePoint markup

ScriptLink tag with encoding

<!--MS:<SharePoint:ScriptLink name="&#60;%=Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl("IntrinsiQ.UserPortal.SharePoint/scripts/portal-main.js", false)%&#62;" runat="server">-->
<!--ME:</SharePoint:ScriptLink>-->

Result: Invalid SharePoint markup

Note: I tested the encodings with "<" = &#60; or &lt; and ">", and &#62; or &gt; for good measeure.

2

Matt,

You can create an user control to handle this in code. You can then add the control to the master page.

Take a look at these two examples and let me know if I can assist.

Inject dynamic javascript using MasterPage

Programmatically add JS/CSS to pages

  • That makes sense; I'll take a look into this. – contactmatt Jun 29 '15 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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