I have a large body of experience working with AppCache-backed applications served by a Rails stack.
I've found the easiest thing by far is to not hardcode your version into your AppCache. You should be generating the file dynamically, and programatically generating a unique value for the version. Ideally, nobody should be introducing change to the manifests themselves, they should be introducing change to the inputs that programatically generate the file.
This isn't really unique to the AppCache. If you find where one specific line needs to be modified in virtually every commit, you probably shouldn't be hard-coding that line. It should be generated in some way, based on whatever changes in the repo prompt a change to that line.
Returning to the AppCache, I've found the easiest thing to do is:
- in development, include the last-modified time of all the files in the appcache
- in production, include the commit ID of the deployed Git commit
I have no idea what language you're using, but in the Rails world, my AppCache manifest looked something like the following. Nobody would ever have to change this file, they would only add or remove files from the @files
array, which is managed in the controller that serves up this manifest:
CACHE MANIFEST
<% if Rails.env.development? %>
<% @cached_files.each do |file| %>
# <%= File.mtime(file) %>
<% end %>
<% else %>
# <%= `git rev-parse HEAD` %>
<% end %>
CACHE:
<% @cached_files.each do |file| %>
<%= file %>
<% end %>
NETWORK:
*
The first part, wrapped in Rails.env.development?
outputs a series of comment lines, containing the last-modified time of every file included in the manifest. This means that, during development, the AppCache will be automatically expired whenever any file included in it is modified.
In production, the AppCache was expired when a new commit was deployed. This might be overkill for you; if you want to avoid needlessly expiring the AppCache of your users, you should do something more clever like hashing the files involved so that the cache expires when their contents change.
In the end, I wound up writing a small library for helping eliminate the repetitive bits of generating manifests. On the off chance you are using Rails, you might find it helpful: https://github.com/meagar/rails_appcache