How do I get appcache to work with PHP (or any server side)?

HTML5 appcache

is a good way to cache client-side assets and make them available when the user goes offline. I've been playing with this technology for some time, and so far it works pretty well with static resources, such as html

, css

, js

, images


Now I have come to a situation where I need to integrate some functionality php

into my application. For simplicity, you can say that mine show_tasks.php

does this,

    // Print the list of task names from the database.


So I put this cached page inside my file myCache.appcache

like this,




Now the problem ...

When the user first accesses this page (given that he is online), the browser caches the html page along with the list of tasks that were there at that moment. But after that, even when it doesn't connect to the database and fetches the latest data. Instead, it always shows the cached version that was cached the first time it was run.

I understand that in order to update the client-side cache, you need to make changes to the file itself show_tasks.php

(not the data it processes) as well as the file myCache.appcache

. (In my case, the change show_tasks.php

won't happen)

I am looking for a solution to make my application work in such a way that

  • If the user is online, read the jobs from the database and show them. (Don't show cached version)

  • If the user is offline, show the cached version, but also the latest updated data. (Quest list when he last accessed it online)

I have considered the question Using appcache with php & database

. But I am wondering if there is another way to achieve this. (Possibly using some client side functionality) Obviously I'm willing to use Javascript / JQuery. What would be a good approach to tackle this scenario?


source to share

All Articles