2

I have a standard SharePoint 2013 Teamsite template with "seattle" masterpage and added jquery in the head of the seattle.html to solve some branding issues(screen 1). The problem is that I always get a javascript error from my browser (screen 2). I tried different things but with no luck, e.g. change the position of the scriptlink tag; I tried to choose different jquery versions (2.1.0, 1.11.0, 1.10.1); I recreated the website. The strange thing is that I don't have any problem with other templates (searchcenter, documentcenter). This behavior only exists with the teamsite template. Would be nice if anybody has an idea to solve this. If you miss some information please ask for them. Thank you!

Screen 1 enter image description here

Screen 2

enter image description here

2 Answers 2

1

Try loading the jQuery using Html script link at the bottom of the head tag (or after OOTB scripts). Better yet, load it from CDN and provide a fallback.

 <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js"></script>  
 <script type="text/javascript" >
        // Fallback   
        (window.jQuery || document.write('<script src="/sites/SiteAssets/scripts/jquery-1.9.1.min.js"><\/script>'));
 </script> 

Your fallback code can reside under Root Site collection's asset library ex. https://sp2013.sharepoint.com/SiteAssets/scripts/jQuery-1.9.1.min.js

3
  • Hi Aveenav, thank you for your help. The problem is that when I don't use the SharePoint:ScriptLink Control that jQuery is loaded too late. With your solution I get the message that "$" is undefined so that jQuery is not loaded.
    – lex
    Commented Mar 27, 2014 at 14:58
  • when you need to load jQuery? Commented Mar 27, 2014 at 15:19
  • @lex, add the above code before any other OOTB scripts(core.js etc..) in your master page. The only thing you need to make sure is any custom javascript that you use should appear after jQuery reference. If the ScriptLink worked for you, ignore this.
    – Aveenav
    Commented Mar 27, 2014 at 21:42
0

OK. It works now. I'am not sure why but the last steps I did was setting the Site back to the default site definition and restartet the server. Than I've added jQuery like described in this answer from Robert Lindgren:

Adding jQuery to master page

However... thank you Aveenav.

4
  • use the ScriptLink for jQuery and set a param to download it when require it's a very no sense option IMHO Commented Mar 27, 2014 at 15:45
  • what do you mean with "set a param to download it when require"? I did't set a param like e.g. OnDemand
    – lex
    Commented Mar 27, 2014 at 15:55
  • Yes that one... I mean usually you need jquery asap and always so imho it better have a script tag on your head tag Commented Mar 27, 2014 at 16:09
  • Also, usually on my project, I deployed jquery and knockoutjs straight to the style library Commented Mar 27, 2014 at 16:22

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.