none
JavaScript API Office.initialize slow performance - Outlook for Android RRS feed

  • Question

  • I am developing a cross-platform JavaScript Add-In. I have stripped my problem down to the skeleton below.

    The behaviour normally is that there is a delay of approx. 200ms before Office.initialize is called. However, on some devices, it takes between 4-10 seconds. I have witnessed it taking 17 seconds on one occasion. These have been on Outlook for Android but I don't know if it would also affect iOS.

    Why would it take such a long time to call initialise and how could I get around this? I never see it take more than a few hundred ms on my own Android device.


    Thanks!


    <html>
    <head>
        <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" crossorigin="anonymous"></script>
    
    </head>
    <body>
        <script>
    
            function log(message) {
                var dateTimeVal = new Date().toISOString().slice(11, -1);
                var appendHtml = dateTimeVal + ": " + message + "<br/>";
                document.body.innerHTML += appendHtml;
            }
    
            Office.initialize = function () {
                log("Office.initialise has been called. Diagnostics: " + JSON.stringify(Office.context.mailbox.diagnostics));
            };
    
            log("Set Office.initialise function. Waiting for callback...");
    
        </script>
    </body>
    </html>


    • Edited by Jonathan Cardy Tuesday, October 16, 2018 10:34 AM Added screenshot
    Tuesday, October 16, 2018 10:30 AM

All replies

  • Hi Jonathan Cardy,

    You must be initialized as a function at the beginning of the code file .

    Office.context property or any another property of office will be available when called from the functions.

    For more information, you could refer to this link:

    office package

    Regards,

    Alina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, October 17, 2018 5:56 AM
  • Hi Alina,

    Thanks, but it isn't related. Office.initialize is correctly initialised as a function. Indeed, it's working correctly for most users. The issue is with a small number of instances of Outlook which take an intermittently long time to call the initialize function.

    Thanks

    Johnny

    Wednesday, October 17, 2018 8:52 PM
  • Hi Jonathan Cardy,

    You could refer to these links:


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    Thursday, October 18, 2018 5:26 AM
  • Those links refer to VSTO, not newer Office Add-Ins: 
    https://docs.microsoft.com/en-us/office/dev/add-ins/overview/office-add-ins

    Thanks

    Johnny

    Friday, October 19, 2018 9:58 AM
  • Hi Jonathan Cardy,

    You could try this code :

    Office.initialize = function () {   

    // Office is ready   

    $(document).ready(function () {     

       // The document is ready   

    }); 

    };

    For more information, please refer to this link:

    https://github.com/OfficeDev/office-js-docs-pr/blob/master/docs/develop/understanding-the-javascript-api-for-office.md

    Regards,

    Alina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    Friday, October 19, 2018 10:14 AM
  • 1 - document loaded is not related to registering Office.initialize or slowness in Outlook calling it

    2 - my document is loaded since the script tag is at the end of the body tag

    Alina, I understand how to build an AddIn, I just am looking for input as to any reasons for Outlook failing to call Office.initialize within a few hundred milliseconds. I suspect it could be related to size of inbox, O365 Exchange response times, or an Outlook for Android app bug. I am hoping to hear from anyone who has encountered this issue or has insight into its causes.

    Thanks!

    Johnny

    Friday, October 19, 2018 10:39 AM
  • Hi,

    Maybe you could try Office.onReady() method.

    Please have a look at this link:

    Understanding the JavaScript API for Office


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Tuesday, October 23, 2018 5:17 AM
  • Thanks for your asking. Did you resolve your issue ? If the post helps you, you can mark it as answer and close the post. Thank you for understanding. If you have any question, or update, please feel free to let us know. I wish you a happy life!

     

    Regards,

     

    Alina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, October 29, 2018 6:18 AM