No commit activity in last 3 years
No release in over 3 years
Generate appcache manifest for your Middleman Project
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Middleman Application Cache

Generate a Application Cache Manifest to support offline access.

Disclaimer

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.

Usage

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.

Configuration

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

cachemanifest

The filename for the generate cache manifest.

Default: 'manifest.appcache'

cache

The list of files, directories, or glob patterns which should be cached.

Default: ['index.html']

network

The list of resources that require the user to be online.

Default: ['*']

fallback

The mapping of fallback resources if a resource is unavailable.

Default: Empty

use_relative

If the resources should be treated as relative from the appcache.

Default: true

version_hash

If a version hash should be generated from the contents of the referenced files.

Default: true

License

Middleman Application Cache created by Ryan Scott is distributed under the MIT license.