javascripthtml5-appcache

Update only one file via application cache


Here is my manifest.appcache file.

CACHE MANIFEST
app.js
theme.css
logo.png

How can I force browser renew the app.js file only?


Solution

  • Application cache works slightly different to what you may think.

    When a new version of the manifest becomes available, the browser goes through all the files and determines which have changed on the server. The browser does this by sending the "If-Modified-Since" header with the request.

    If the file hasn't been modified, the server will return code 304 (not modified) and the browser will skip the download and move to the next file.

    Only files that have been modified get refreshed.

    It's also a good idea to include a version or hash in the manifest, so a new manifest is always downloaded and checked.

    In example, I use a php script to dynamically generate my appcache.manifest. The script md5's all the included files to produce a hash/version number that's included in the manifest.