-5

I am using SharePoint framework and until some recent changes in master page everything worked well, but after removal of few scripts, minification and bundling, few users started complaining that page crashed with error "The value of the property '$' is null or undefined, not a Function object". The way script is added seems correct, in bundle it is placed first, and it is not browser based issue (tried same browsers as client), so the only reason I thought of was so that my custom script (which resides at the end of body section) starts working before jQuery is loaded (in head section). If so, how to prevent it without loosing performance? If not, what could be other causes?

I use user control to add jQuery, which is registered in master page with few other javascripts and css

<asp:PlaceHolder runat="server" ID="phSkin">
   <script type="text/javascript" src="<%= pathToJS %>"></script>
</asp:PlaceHolder>

The master page looks roughly like that (tried to minify as mush as I can)

<%@ Register TagPrefix="nf" TagName="CssSkin" Src="path_to_user_control" %>
<html>
<head>
 //few initializations
    <nf:CssSkin runat="server" __designer:Preview="
    &lt;link type=&quot;text/css&quot; href=&quot;/path/GetBrandSiteSkin.ashx&quot; rel=&quot;stylesheet&quot; /&gt;    
" __designer:Values="&lt;P N='TemplateControl' R='0' /&gt;"/>
</head>
<body>
//layout formating
   <script type="text/javascript" src="path_to_custom.js"></script>
</body>
</html>
Vilius
  • 786
  • 1
  • 6
  • 14
  • 1
    Please provide a [small, reproducible example of the code](http://stackoverflow.com/help/mcve) in question so that we are able to see what you are seeing. – GoBusto Mar 18 '15 at 09:45

1 Answers1

0

You can try to use SP.SOD.executeOrDelayUntilScriptLoaded

Max
  • 6,821
  • 3
  • 43
  • 59
  • Thought about this solution, but this solution would increase performance time, which is a big no in my scenario. – Vilius Mar 18 '15 at 11:03
  • 1
    Another solution can be to [load jquery dynamically](http://stackoverflow.com/questions/10113366/load-jquery-with-javascript-and-use-jquery) on your custom script. – Max Mar 18 '15 at 11:55
  • Well, this is little bit more suited, but still haven't tested it so it is worth trying – Vilius Mar 18 '15 at 14:00