Use HTML5 appCache with Django dynamic page

By | July 12, 2018
Questions:

I am experimenting the HTML5 appCache feature as our web app uses a lot of image resources. Also most pages are not static, but dynamic pages based on Django.

The problem is that when appCache is used for a page (more like a RESTFUL url), it will automatically download this page, but it seems there is no way to force invalidate this page when there are content updates on this page without changing the manifest file on the server side.

My question is, does this mean I can’t use appcache on any dynamic pages? if not, how do I do it?

Answers:

Manifest files in HTML5 aren’t intended to handle dynamically changing resources. It’s purpose is common and constant assets used application-wide: things like CSS, JavaScript, and interface elements (icons, buttons, logos, backgrounds, etc) that make up the look and feel of the application (even if not used on the current view). This allows the common assets to be prefetched and cached, so that each view only has to load it’s individualized content.

Questions:
Answers:

I think we have a similar problem:

My HTML5 Application Cache Manifest is caching everything

I haven’t found the ultimate answer but from what I’ve learned it seems that the manifest is not meant to be set on every page. Again I’m not sure but this is a hack that I came across. I have a page such as manifest.html that has the

<html manifest="manifest.appcache"> 

I learned that pages which do not have this will not be added to the cache however they will still continue using the application cache if on the same domain. Therfore if you include manifest.html a plain html page that has this in an iframe on everypage it will not cache that page like chrome will no longer output:

Adding master entry to Application Cache with manifest 

but if you go to network tab you will see that it is using the cache

so basically instead of manifest attribute on html tag put this in the beginning of body:
<iframe id='manifest_iframe_hack' style='display: none;' src='temporary_manifest_hack.html'>

content of temporary_manifest_hack.html:

<!DOCTYPE HTML>
<html lang="en" id="sexxymofo" class="no-js" manifest="manifest.appcache">
    <head>
        <meta charset="utf-8">
        <title>Hack 4 Manifest</title>
    </head>
    <body></body>
</html>

now since you didn’t specify your problem specifically I am worried you might have an issue with a valid manifest, keep in mind there is no wildcards in the manifest, use this url to validate:
http://manifest-validator.com/validate

the simplest error will cause the manifest to be invalid and no appcache will be used, use chrome
for debugging as the console will log every step of the process, also see this url in chrome:
chrome://appcache-internals/

Again take a look at my question in the answer above to learn more

Leave a Reply

Your email address will not be published. Required fields are marked *