0

I am using jquery for a small webapp and I've built in the option for the app to be available offline - to do so I force reload a page and if it has the correct parameters it uses a simple PHP $_GET to add the manifest line into the html tag, which then triggers the app cache.

I have tried:

$.mobile.changePage

But it fails to trigger the appcache properly. The only way I've been able to do it is to use:

window.location.href = window.location.href + "?appcache=true"

This works! However I get an 'Error Loading Page' for a split second before the page reloads.

Is there a way of either disabling this message or a different way of achieving the same outcome without the message?

Thank you.

2 Answers2

0

Have you tried to use two pages, something like this: yourpage.php and yourpageappcache.php and in yourpageappcache.php:

<?php header('Location: yourpage.php?appcache=true');?>
Ouadie
  • 13,005
  • 4
  • 52
  • 62
  • Thanks for your reply Ouadie. I've tried putting the appcache on a separate page. I link from the index file to appcache.php which has the manifest in the HTML tag. However it fails to trigger unless I manually refresh the page (or use the js as above to do so). If I take jQuery mobile out of the equation it runs the appcache fine on the new page so I'm not sure if it's caching the data beforehand or something… – Chris Boakes Sep 19 '13 at 13:32
  • have you tried to disable `jQuery mobile` cache ? http://jquerymobile.com/demos/1.2.0/docs/pages/page-cache.html Can you post more lignes of your code ? – Ouadie Sep 19 '13 at 14:18
  • Thanks for your help so far. I've just tried disabling the cache by adding `data-dom-cache="false"`. So far I have an index page which has a link like so `Click here` which goes to cachepage.php and in the html tag of that page it reads ``. This works fine if the page is visited separately (or force refreshed with the javascript line) and if I disable jQuery mobile too. Not sure if it's prefetching the data automatically before I visit the page? – Chris Boakes Sep 19 '13 at 16:12
0

I managed to solve the issue by disabling ajax before jQuery mobile has loaded. As in this answer: How To Disable Ajax In jQuery Mobile Before Page Load?

So BEFORE jQuery mobile is called:

<script type="text/javascript" src="jquery"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
});
</script>
<script type="text/javascript" src="jquerymobile"></script>

This allows me to link to another page running the appcache (and with ajax enabled).

Thanks for your help.

Community
  • 1
  • 1