MVC Dynamic Appcache Manifest and Google Chrome “Application Cache Error event: Failed to parse manifest”

For MVC, dynamically generate a manifest for appcache has one common problem:

Problem:

You have an AppManifestController and you have a view.

Google chrome will give the error message “Application Cache Error event: Failed to parse manifest

   1: @{

   2:     Layout = null;

   3:     HttpContext.Current.Response.ContentType = "text/cache-manifest";

   4: }

   5: CACHE MANIFEST

   6:  

   7: CACHE:

   8: https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js

 

Cause:

If you use Fiddler or just view source via browser, you will see the generated manifest has an empty first line instead of “CACHE MANIFEST”.  That screws things up.

Solution

You want to Response.Write() instead.

   1: @{

   2:     Layout = null;

   3:     HttpContext.Current.Response.ContentType = "text/cache-manifest";

   4:     // must write out explicitly or else the first line will be empty, making the cache manifest not parseable by browser.

   5:     Response.Write("CACHE MANIFEST");

   6: }

   7:  

   8: CACHE:

   9: https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js

Advertisements

One thought on “MVC Dynamic Appcache Manifest and Google Chrome “Application Cache Error event: Failed to parse manifest”

  1. Thanks, that saved my life. I was struggling with that for the last 2 days. I found lots of too complicated answers but this one simple worked (I saw the empty line, but I was trying to remove it with setting the layout = null or smt like that. It didnt work). Thanks again 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s