title: Conditionally load Office.js when webapp is loaded as Outlook Add-in
body: <p>I'm currently building a web application that can be loaded both as a standalone version in the browser and as an Outlook Add-In. To make use of the Outlook environment, I'm loading office.js within the layout of my web app. I'd like to check whether the webapp is loaded within Outlook (as an add-in) or as a web-app in the browser, so that I can conditionally hide features that require the app to run within Outlook.</p>
  
  <p>According to the existant question on the topic (found here: <a href="https://stackoverflow.com/questions/44989152/check-if-office-js-is-loaded-outside-of-office-client">Check if Office.js is loaded outside of Office client</a>) office-js-helpers provide that kind of information through the use of</p>
  
  <pre class="lang-js prettyprint-override"><code>OfficeHelpers.Utilities.host
  </code></pre>
  
  <p>This returns either "outlook" or undefined depending on the context, which is exactly what I'm looking for (with the caveat that you first load office.js and then another to script to check whether office.js is actually needed). Unfortunately I have to support older releases of Outlook for which the solution above returns undefined even when loaded within outlook (up to 2 years behind the recent version - no change in sight).</p>
  
  <p>Interestingly enough, office.js itself (or rather a dependency of it, o15apptofilemappingtable.js, <a href="https://appsforoffice.microsoft.com/lib/1.1/hosted/o15apptofilemappingtable.js" rel="nofollow noreferrer">https://appsforoffice.microsoft.com/lib/1.1/hosted/o15apptofilemappingtable.js</a>) already has a line in the minified JavaScript that is able to figure out that office.js is loaded outside of an Outlook environment and prints a warning:</p>
  
  <pre class="lang-js prettyprint-override"><code>if(d._hostInfo.isRichClient){var e,a,u="Warning: Office.js is loaded outside of Office client",
  </code></pre>
  
  <p>Again this is exactly what I'm looking for, but I can't seem to wrap my head around how I could implement a check like that myself.
  I'm aware that you can check whether Office.js is fully loaded through the use of Office.onReady()(as seen here: <a href="https://docs.microsoft.com/en-us/office/dev/add-ins/develop/understanding-the-javascript-api-for-office" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/office/dev/add-ins/develop/understanding-the-javascript-api-for-office</a>), yet what I want is to check BEFORE office.js is loaded whether or not it is actually necessary (which it isn't when the application runs outside the Outlook environment). </p>
  
  <p>Did someone run into a similar scenario and might share his insight?</p>