Generate a Application Cache Manifest to support offline access.
I have developed this for the intention of using it exclusively for single page applications.
While it can be extended to support App Cache Manifests for multiple pages, I have no intent at this point in time to develop support for this.
If it is something that you do need, please let me know and I'll investigate how it could work without compromising the configuration syntax.
Add the following line to Gemfile
, then run bundle install
:
gem 'middleman-appcache'
Add a link to the appcache name in you html layout:
<html manifest="manifest.appcache">
...
</html>
And active the extension inside config.rb:
activate :app_cache do |config|
config.cache_manifest = 'manifest.appcache'
config.cache = %w(index.html favicon.ico stylesheets/*.css javascripts/*.js images/*)
end
Then when you run middleman build
, the application cache will be generated in the build directory.
The extension has 5 optionally configurable fields:
activate :app_cache do |config|
config.cache_manifest = 'manifest.appcache'
config.cache = %w(index.html offline.html favicon.ico stylesheets/*.css javascripts/*.js images/*)
config.network = %w(/ /login /logout)
config.fallback = {
'/' => 'offline.html'
}
config.use_relative = false
config.version_hash = true
end
The above configuration will generate the following appcache:
CACHE MANIFEST
# version 1aadc03fe3f695a96d64f1a190b6253e
CACHE:
/index.html
/offline.html
/favicon.ico
/stylesheets/all-3676b7b2.css
/stylesheets/normalize-6197e73d.css
/javascripts/all-24162989.js
/javascripts/vendor-e28aee79.js
/images/welcome-64a62e79.png
NETWORK:
/
/login
/logout
FALLBACK:
/ /offline.html
The filename for the generate cache manifest.
Default: 'manifest.appcache'
The list of files, directories, or glob patterns which should be cached.
Default: ['index.html']
The list of resources that require the user to be online.
Default: ['*']
The mapping of fallback resources if a resource is unavailable.
Default: Empty
If the resources should be treated as relative from the appcache.
Default: true
If a version hash should be generated from the contents of the referenced files.
Default: true
Middleman Application Cache created by Ryan Scott is distributed under the MIT license.