Search code examples
asp.net-mvchtmloffline-caching

Apply cache manifest only in production mode


I've added a "cache.manifest" in my application (this works perfectly) and since then, it's very hard to debug since I must always clear the cache or modify the cache.manifest version.

I tryied to load the manifest with "HttpContext.Current.IsDebuggingEnabled" condition:

<!DOCTYPE HTML>
  @if (HttpContext.Current.IsDebuggingEnabled)
  {
    <html>
  }
  else
  {
    <html manifest="/cache.manifest">
  }

This doesn't works and Visual Studio gives me 3 errors:

  • The block is missing a closing } character
  • html element is not closed
  • Can't have more than 1 html element.

Does anyone have an idea ?

Thanks !


Solution

  • Based on the answer from "sav931", I finally found the solution:

    <html @(HttpContext.Current.IsDebuggingEnabled ? "" :  "manifest=cache.manifest" )>
    

    No need to add an app setting key in the web.config, since there's already a function for that. (HttpContext.Current.IsDebuggingEnabled)

    Also, I removed the manfest attribut completely when developping.