1

We usually reference js files using tokens ~site and ~sitecollection and putting below into the masterpage:

<SharePoint:ScriptLink language="javascript" name="~sitecollection/files/abc.js" runat="server" Localizable="false" />

We now want to consolidate some shared files, e.g. libraries, i.e. we want to have our site collections reference files located on one particular site collection hosting those. This is to make it easier to update the JS code base in case of upgrades. The following does obviously not work:

<SharePoint:ScriptLink language="javascript" name="https://hosting.server.com/files/abc.js" runat="server" Localizable="false" />

Any idea how to do this w/o dynamically loading JS files via JavaScript itself?

0

I seemed to be too much in SharePoint lately.

The solution is to simply put normal HTML tags instead (xxx being the hosting site collection):

   <link rel="stylesheet" type="text/css" href="/sites/xxx/Files/css/fancytree.css"></link>

and

   <script src="/sites/xxx/Files/libs/pre.js" type="text/javascript" language="javascript"></script>
  • 1
    You still need to update the masterpages. If you apply one UserCustomAction ScriptLink, it can then add all additional CSS and JS to the document.head, and you won't have to touch those MasterPages again. – Danny '365CSI' Engelman Mar 1 '17 at 9:24

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.