locked
Use css and js files stored in host web RRS feed

  • Question

  • Hello,

    I am creating a SharePoint hosted app. I would like to use css and js files which are stored in the host web or root site of host web's site collection. 

    I tried <SharePoint:CSSRegistration> and <SharePoint:ScriptLink> with ~sitecollection but it is not working. Could anyone guide me how to use this?

    Thank you.

    Regards,

    SuPar

    Thursday, January 22, 2015 6:34 PM

Answers

  • My Suggestion would be to dynamically load them.

        var scriptbase = hostUrl + "/_layouts/15/";
        promise = $.getScript(scriptbase + 'MicrosoftAjax.js')
            .then(function () {
                return $.getScript(scriptbase + 'SP.Runtime.js');
            })
            .then(function () {
                return $.getScript(scriptbase + 'SP.js');
            })
            .then(function () {
                return $.getScript(scriptbase + 'SP.RequestExecutor.js');
            })
            .then(function () {
                return $.getScript(scriptbase + 'init.js');
            })
            //.then(function () {
            //    return $.getScript(scriptbase + 'PS.js');
            //})
            .then(function () {
    
    
            })
            .always(function () {
               // msls_mark(msls_codeMarkers.loadSharePointEnd);
            });

    Thursday, January 22, 2015 11:28 PM

All replies

  • Hello!

    Try to use this article:

    Link

    I hope that it will help you!

    • Proposed as answer by Daniel Muth Thursday, January 22, 2015 6:48 PM
    • Edited by Daniel Muth Thursday, January 22, 2015 6:50 PM
    • Unproposed as answer by Eric Tao Tuesday, February 3, 2015 6:03 AM
    Thursday, January 22, 2015 6:48 PM
  • My Suggestion would be to dynamically load them.

        var scriptbase = hostUrl + "/_layouts/15/";
        promise = $.getScript(scriptbase + 'MicrosoftAjax.js')
            .then(function () {
                return $.getScript(scriptbase + 'SP.Runtime.js');
            })
            .then(function () {
                return $.getScript(scriptbase + 'SP.js');
            })
            .then(function () {
                return $.getScript(scriptbase + 'SP.RequestExecutor.js');
            })
            .then(function () {
                return $.getScript(scriptbase + 'init.js');
            })
            //.then(function () {
            //    return $.getScript(scriptbase + 'PS.js');
            //})
            .then(function () {
    
    
            })
            .always(function () {
               // msls_mark(msls_codeMarkers.loadSharePointEnd);
            });

    Thursday, January 22, 2015 11:28 PM