1

I am working on a sharepoint online 2013. and inside my team site collection, i am adding some script editor web parts which uses jQuery. and for sharepoint to understand jQuery code i need to reference the jQuery source file for example jquery-1.10.2.js. so now i know that i can modify the master page (seatle.master) and add i reference to jQuery. but i am not sure if i can add a reference to jQuery without directly modifying the seatle.master, in the same way i add a reference to custom css , by going to "site setting>>look and feel>> master page>> set the Alternate CSS URL"?? so is this possible??

  • 2
    Staple it to the site as a UserCustomAction, github.com/OfficeDev/PnP/tree/master/Samples/…. I'll give a better answer in the morning. – Eric Alexander Nov 15 '16 at 4:23
  • @EricAlexander thanks will be waiting for more details. again i am working on sharepoint online 2013. – john Gu Nov 15 '16 at 8:57
  • 1
    Danny covered it, with Alternate CSS and UserCstomActions, there is no need to modify the master page, at all. – Eric Alexander Nov 15 '16 at 13:05
  • @EricAlexander I agree that using UserCustomActions & Alternate CSS, can minimize the need to modify the master page. unless the modification requested by the customer can not be achieved using alternate css & UserCustomAction. For example if the customer requested to move the site logo to be on the left upper corner of the window, to relocate the search box to be on the right upper corner and to display the current date/time below the user-name. then those kind of modification require to modify the master pages directly and can not be achieved using pure UserCustomactions is this correct ?. – john Gu Nov 20 '16 at 2:17
  • they aren't real valid reasons to alter the master page in my opinion, i would say no, we aren't going to do that. – Eric Alexander Nov 20 '16 at 14:53
3

You have multiple options:

  • load JS files with JSLink assigned to a WebPart, easy to do with the SharePoint UI, but less easy to maintain (and you need a WebPart that can do JSLink on the page)

  • set UserCustomAction ScriptLinks, these are functionaly the same as MasterPage ScriptLinks and JSLinks but are stapled on the SiteCollection or only one Web.
    They do not require any changes to the MasterPage
    They are also executed on System Pages (where your MasterPage script is not executed)
    But you can only set them with code.
    UCAs have been around since SP2010, and the best kept secret
    (note: alas Microsoft decided to remove them from the Modern Experiences (they did work in the first Preview) They work fine in Classic Mode.

Adding UserCustomActions

  • ok thanks for your reply. now i agree with you is that referencing jQuery using JSLINK will cause a maintainability problems , when i have many web parts, and i prefer to reference jQuery all over the site collection from one place. second point i did not understand if you are trying to say that using UserCustomActions is not a recommended appraoch as it is considered an old appraoch ? – john Gu Nov 15 '16 at 12:28
  • 1
    UserCustomActions ScriptLinks are the best way to not change your MasterPage, they have been around since 2010,have always been and still are the most powerful way of adding script. (except on Modern Experiences.. nothing can be loaded in Modern Experiences – Danny '365CSI' Engelman Nov 15 '16 at 13:30
  • 1
    Hardly anyone knows about them.. even MVPs still stuff stuff in the MasterPage – Danny '365CSI' Engelman Nov 15 '16 at 17:03
  • 1
    Yes, I think 7 out of 10 projects I am called into to clean the mess still changed the MasterPages – Danny '365CSI' Engelman Nov 16 '16 at 8:24
  • 1
    My opinion: Do whatever you want with MasterPages; know that Microsoft now advices against them, know that with (more and more) Modern Experience the concept of a MasterPage is gone. – Danny '365CSI' Engelman Nov 18 '16 at 10:25

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.