title: Blazor Component Javascript Errors (Microsoft.JSInterop.JSException)
body: <p>I have a pretty basic Javascript function stored in a separate JS file that sets the page title for a new Blazor app that looks like this:</p>
  <pre><code>window.setTitle = (title, icon) =&gt; {
  
      //title
      document.title = title;
      $(&quot;#page_title&quot;).html(title);
  
      //page icon
      $(&quot;#page_icon&quot;).removeClass().addClass('fad fa-' + icon + ' fa-2x');
  }
  </code></pre>
  <p>It all works great, except on a cold startup of the app when hitting it through a browser. When I try to hit the site and it hasn't been hit in a little while, I'll end up with the following in the console:</p>
  <pre><code>Microsoft.JSInterop.JSException: Could not find 'setTitle' ('setTitle' was undefined).
  Error: Could not find 'setTitle' ('setTitle' was undefined).
      at https://example.com/_framework/blazor.webassembly.js:1:1287
      at Array.forEach (&lt;anonymous&gt;)
      at e.findFunction (https://example.com/_framework/blazor.webassembly.js:1:1247)
      at b (https://example.com/_framework/blazor.webassembly.js:1:2989)
      at https://example.com/_framework/blazor.webassembly.js:1:3935
      at new Promise (&lt;anonymous&gt;)
      at Object.beginInvokeJSFromDotNet (https://example.com/_framework/blazor.webassembly.js:1:3908)
      at Object.w [as invokeJSFromDotNet] (https://example.com/_framework/blazor.webassembly.js:1:64218)
      at _mono_wasm_invoke_js_blazor (https://example.com/_framework/dotnet.5.0.6.js:1:190800)
      at do_icall (&lt;anonymous&gt;:wasm-function[10596]:0x194e4e)
     at Microsoft.JSInterop.JSRuntime.&lt;InvokeAsync&gt;d__15`1[[System.Object, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
     at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
     at App.Web.Portal.Client.Shared.PageTitle.OnAfterRenderAsync(Boolean firstRender)
     at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
  d.printErr @ blazor.webassembly.js:1
  </code></pre>
  <p>The part that confuses me is, if I just do a hard refresh (CTRL + Shift + R), then everything loads up perfectly fine and runs great <strong>without any changes or deployments</strong>. Given that, I don't really know what to do or where to look on how to correct this.</p>
  <p>Has anyone else seen this before or have any tips on how to prevent it? I've been doing .Net since ~2003, but I'm new to Blazor as of 2021, so I've been learning a LOT, but this one has me stumped.</p>
  <p>Thanks in advance!</p>