Search code examples
androidiphonedjangohtmlhtml5-appcache

HTML5 Offline web apps NOT working in Android 2.x, iPhone. (However works in Android 4.0)


Trying to implement offline feature of HTML5. After doing a lot of googling, this is how my code looks. (It's a django project; deployed in apache2.2 with mod_wsgi plugin)
HTML
`

<!DOCTYPE HTML>
    <html manifest="{{MEDIA_URL}}cache.manifest">
       <head>
          <meta charset="utf-8">      
          <title>MyHomeStuff</title>      
          <script type="text/javascript" src="{{MEDIA_URL}}MyHomeStuff.js" ></script>
          <script></script>
       </head>
       <body>
         .............
       </body>
    </html>

`

Apache conf\mime.types
text/cache-manifest manifest

\Python27\Lib\mimetypes.py
Added '.manifest': 'text/cache-manifest', into types_map dict

(With the above addition to mimetypes.py, it started working for android 4.0)

cache.manifest
CACHE MANIFEST
CACHE:
index.html
MyHomeStuff.js

EDIT:
views.py `

def offlineApp(request):
    t = get_template('index.html')
    html = t.render(Context({'MEDIA_URL':'http://myDomain.com/site_media/'}))
    return HttpResponse(html)

EDIT2
Is it required to use any specific module/middleware to handle text/manifest in django ?

The app works as expected for chrome, opera and other desktop browsers; but doesn't load when in airplane mode for android 2.x, iPhone browsers. However it works with Android 4.0 browser!
What could be the problem? Please help.


Solution

  • Got an answer from google groups here..

    Essentially it tells this:

    when you're serving offline HTML5, you need to serve (at least) 2 pages -- a page with html, and a completely separate second page containing the manifest. The manifest file has a content type of text/cache-manifest; your HTML is served with a normal text/html content type.