title: Cache-Control JSS / JS Files in Server Side Blazor
body: <p>I want to improve browser caching in case of writing Cache-Control max-age Header attribute.
  For this i found this helpful page:
  <a href="https://www.meziantou.net/caching-static-resources-forever-with-asp-net-core.htm" rel="nofollow noreferrer">https://www.meziantou.net/caching-static-resources-forever-with-asp-net-core.htm</a></p>
  <p>But when trying this in Server Side Blazor the whole application stops running.</p>
  <p>As long as I use the following code (also if not JS is filtered) the Blazor app won't run:</p>
  <pre><code>            app.UseStaticFiles(new StaticFileOptions()
          {
              OnPrepareResponse =
                  r =&gt;
                  {
                      string path = r.File.PhysicalPath;
                      if (path.EndsWith(&quot;.gif&quot;) || path.EndsWith(&quot;.jpg&quot;) || path.EndsWith(&quot;.png&quot;) || path.EndsWith(&quot;.svg&quot;))
                      {
                          TimeSpan maxAge = new TimeSpan(7, 0, 0, 0);
                          r.Context.Response.Headers.Append(&quot;Cache-Control&quot;, &quot;max-age=&quot; + maxAge.TotalSeconds.ToString(&quot;0&quot;));
                      }
                  }
          });
  </code></pre>
  <p>Browser F12 view:</p>
  <p><a href="https://i.stack.imgur.com/dGmu2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dGmu2.png" alt="enter image description here" /></a></p>
  <p>Any idea what causes this and how to fix it (use Cache-Control for all but the important Blazor JS files) ?</p>