Appcache in Cordova app
Asked Answered
B

2

7

I'm developping a mobile app using Cordova (3.4). My core application files are embedded in my app archive (.apk or .ipa), and some files (js/html/css) must be retrieved from my server. So if I want my application usable offline I need to use appcache for these files.

A sample of my appcache.manifest :

CACHE MANIFEST
# version 7


NETWORK:
*
http://*
https://*

CACHE:
# Message module
http://my.server.ip/module/routes.json
http://my.server.ip/module/css/style.css
http://my.server.ip/module/js/controller.js
http://my.server.ip/module/js/service.js
...

My index.html (embedded into my app) :

<!DOCTYPE html>
<html lang="en" xmlns:ng="http://angularjs.org" id="ng-app" ng-app="app" 
                          manifest="http://my.server.ip/tmp_appcache.manifest">
...
<body>
<script>
    document.addEventListener("deviceready", function(e) {
        var appCache = window.applicationCache;

        alert('device ready');

        console.log('appCache', appCache);
        // Fired after the first cache of the manifest.
        appCache.addEventListener('cached', function(event) {
            console.log(event);
            alert('Appcache OK');
        }, false);

        appCache.addEventListener('UpdateReady', function(event) {
            console.log(event);
            alert('Appcache Reloaded');
        }, false);


        appCache.addEventListener('error', function(event) {
            console.log(event);
            alert('Appcache ERROR');
        }, false);

        appCache.addEventListener('checking', function(event) {
            console.log(event);
            alert('Appcache CHECKING');
        }, false);

        appCache.addEventListener('downloading', function(event) {
            console.log(event);
            alert('Appcache DOWNLOADING');
        }, false);

        appCache.addEventListener('noupdate', function(event) {
            console.log(event);
            alert('Appcache NOUPDATE');
        }, false);

        appCache.addEventListener('obsolete', function(event) {
            console.log(event);
            alert('Appcache OBSOLETE');
        }, false);
    }, false);
</body>
</html>

My problem is, when I launch my pp (on Android AND iOS), I didn't see any of my alert (except the "device ready"), and no file is cached.

If I open the url of my webapp in the device browser I actually see my alert.

Is there an additional configuration to do in Phonegap to allow appcache ?

I've seen some article about enabling appcache in Android, but it seems to be for older version of cordova, furthermore it doesn't work for me and if it's the origin of my problem, appcache should work on iOS.

Any idea would be helpful. Thanks

Breastbone answered 25/3, 2014 at 10:25 Comment(4)
Been looking for an answer to the same question for a couple of hours and havent found a clear (and working) way of using html5 cache manifest so far...Xylina
I've created an issue on Cordova JIRA.Breastbone
Another JIRA concerning this problemBreastbone
Maybe this post can help you artem.savelev.com/2012/08/phonegap-cordova-appcacheRowles
S
1

AppCache is not supported in Cordova 3.4 and up to 4.0 and no plans for support that standard in the near future (as of 17/Apr/2015).

Scientific answered 16/4, 2015 at 23:51 Comment(0)
H
-1

Basically you dont require app cache. Check the below link for more clarity.

https://www.raymondcamden.com/2015/02/26/reminder-you-dont-need-appcache-for-phonegapcordova

Hawley answered 28/12, 2016 at 5:36 Comment(2)
You didn't understand my problem, as I said My core application files are embedded in my app archive (.apk or .ipa), and some files (js/html/css) must be retrieved from my server. So this article isn't relevantBreastbone
Ok I got it. I am not sure about your exact use case, but as a best practice please try to keep the files in your app bundle in case if you want those to be used available offline.Hawley

© 2022 - 2024 — McMap. All rights reserved.