3

I am working on an enterprise wiki .aspx page layout. and i added the following script inside my page layout:-

<SharePoint:Scriptlink runat="server" Name="~sitecollection/Resources/PageLayout.js" Language="javascript" />
</asp:Content>

but the script is not having any effect. now if i add a reference to the same script as follow:-

<script src="/HR/Info/Resources/PageLayout.js"></script></asp:Content>

then the script will work as expected... but as i know it is better to use SharePoint:Scriptlink over <script src="">.but seems when i am refereeing the script using SharePoint:Scriptlink the order of the script will be as follow:-

enter image description here

while using the <script src=""> then the script will loaded at the end of the page, and i will get the effect i want...so can anyone adivce how i can fix this?

Hint i tried adding Defer="true" as follow:-

<SharePoint:Scriptlink runat="server" Name="~sitecollection/Resources/PageLayout.js" Defer="true"  Language="javascript" />

but did not fix the problem...

0
1

ScriptLink being "better" to use does not mean it is the best thing to do all the time..

Your scenario requires adding a script as the last one in HEAD of the MasterPage because ScriptLinks are executed early,
and SharePoint will load other SP scripts (like sp.js and core.js) later.

If you do not want to change the MasterPage
(that is why ScriptLink is 'better'... but only the ones added as UserCustomActions not the ones you add manualy in the MasterPage, )
You have to add a ScriptLink Script which will wait for a page/DOM load ready event and then add your required-to-load-last script

1
  • thanks for the help.. so if i use LoadAfterUI="true" will it wait for a page/DOM load ready event ??
    – john Gu
    Mar 1 '17 at 17:02
2

You could try adding LoadAfterUI="true" to you scriptlink tag.

Here is the msdn documentation for the property.

1
  • LoadAfterUI="true" did not work in my case
    – john Gu
    Mar 1 '17 at 17:03

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.