Caching php pages in HTML5 appcache

I am developing a standalone application that also has a set of .php pages. Currently, I have placed these php files in .appcache manifest files and it works fine. But the problem is that although I'm online, when I try to access a php page, it loads the cached version. I prefer this kind of functionality,

  • If online, connect to the server and download the latest information and overwrite the cached new information.
  • If offline - show the latest updated html static page.

Here is my manifest file .appcache file

CACHE MANIFEST #2 taskmanager.php public/css/bootstrap.css.map public/css/bootstrap.min.css public/css/bootstrap-theme.css.map public/css/bootstrap-theme.min.css public/css/main.css public/css/task-manager.css public/js/app.js public/js/taskmanager.js public/js/offlink.js public/js/jquery-2.1.4.js public/js/bootstrap.min.js NETWORK: * http://* 

What taskmanager.php does is read the tasks from the database and display them. When I cache it as above, it will always display a list of tasks when it was loaded for the first time. Even when I'm online, it does not call the database and does not receive new records. Instead, it is loaded from the cache. So my solution was to put it in the FALLBACK section, as mentioned in the first answer. Even if I put the taskmanager.php file in the FALLBACK section, as shown below,

 FALLBACK taskmanager.php static_taskmanager.php 

Now, if I have an Internet connection, taskmanager.php will be launched and will show me the latest tasks. But I want to make static_taskmanager so that it is in sync with these latest task sets. This means that when the user goes offline, static_taskmanager.php will show the most recent list of tasks that taskmanager.php returned when the user was online). But at the moment it works like a full static page.

  • Can this be done?
  • How can I solve this problem?

EDIT

As I understand it, browsing through SO and Google, one way to achieve this is to load dynamic content using AJAX. But I wonder if this can be done using only the manifest file itself.

+5
source share
1 answer

How about using fallback?

Fallback

The FALLBACK section tells the browser what to service when the user tries to access an unencrypted resource offline. Because of this, it is slightly different from CACHE and NETWORK. It contains two values ​​per line, separated by a space. The first value is the URI request, and the second is the resource sent during the mapping. This caches the resource on the right for offline use, so this should be an explicit path. ( http://html5doctor.com/go-offline-with-application-cache/ )

 FALLBACK: /main.php /static.php 

In this configuration, requests to /main.php will be served if the user is not offline, in which case the user will see the latest cached version of /static.php.

Remember that updating assets on your server will not result in a cache update. You must modify the manifest file. In this case, you may need to update the manifest with a version comment or timestamp when creating a new version of static.php.

 # Generated: 2015-07-23 10:34a 

Late notes

In this case, I would recommend deleting main.php from the cache or have a static reserve that allows the user to know that he is looking at older content. The reason is that even if static.php is updated, if the user is disconnected and does not receive this update, he will still see the old content.

If you see performance problems and want to reduce the load on the server, you can create a static version of main.php using wget, for example:

 wget http://example.com/main.php -O main.html 

This will save the contents of the page as HTML. Running as a cron job, it can be updated every five minutes or so.

An alternative is to update static.php and appcache every time, which is likely to reset all assets - thus defeating the intent of the cache.

+1
source

All Articles