none
How to call .JS file at end of page load? RRS feed

  • Question

  • I have a Java script file which will call at end of Body tag.Then only my page performance will improve.

    Please help where i have to call my .js file, to add it at end of the page event in SharePoint 2013.

    Master page/pageLayout?


    Wednesday, June 26, 2019 1:11 PM

All replies

  • Hi Sudhir,

    load javascript after whole page load. below article for your reference:

    https://stackoverflow.com/questions/16936250/sharepoint-2013-add-javascript-after-whole-page-load

    Thanks & Regards,


    sharath aluri

    Wednesday, June 26, 2019 1:23 PM
  • where i have to write this script block ?

    either in master page or page layout?Please explain the correct placeholder ID.

    i nee this functionality should be entire SharePoint site collection level.


    Thursday, June 27, 2019 6:11 AM
  • Not a developer at heart but if you add a script tag in the code near the top.

    <script type = 'text/javascript'>
    
    
    </script>
    
    or 
    
    <script>
    
    </script>


    Then use the document.ready fuction for it to run after page load

    $(document).ready(function(){
      $("button").click(function(){
        $("p").slideToggle();
      });
    });

    It's recommended (well in the last place I worked) that you do not hardcode your javascript into the page, but reference to it and save it in a SharePoint list local to that site collection:

    <script src="myscripts.js"></script>
    Just dont be scared if the code you placed breaks the page. Just keep movinging it under tags until it works. I can't remember from the top of my head which tag it is


    If this is helpful please mark it so. Also if this solved your problem mark as answer.

    Thursday, June 27, 2019 6:58 AM
    Moderator
  • Hi Sudhir,

    In Master Page, you could directly embed the script block in MasterPage.html <head> tag:

    In page layout, you could embed the script block in PlaceHolderMain tag like this:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Proposed as answer by Nagendra Pal Thursday, June 27, 2019 8:11 AM
    Thursday, June 27, 2019 7:10 AM
  • Hi,

     

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

     

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

     

    Thanks

     

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, July 3, 2019 1:48 AM