Rich functionality hurts perceived speed for the iPhone My Thoughts on the iPhone so far
Jun 28

Google Gears Manifest Generator

Google, Tech Add comments

One of the modules that makes up Google Gears is the LocalServer that allows you to capture web resources so they can be served up when a user is offline.

The ManagedResourceStore component allows you to declare which resources you want the LocalServer to capture for you. You use a simple JSON manifest file that you can maintain with any text editor.

However, if your application gets large (lots of resources) you may not want to manage it in this way, so I created an open source Ruby library that allows me to generate this file given some rules:

For example, this will generate the manifest as a json string, and create entries using the current directory and sucking in everything apart from files starting with a ‘.’.

json = do |m|
m.version = 'MyNewVer'
m.add_entry({ :url => 'main.html', :src => 'foo.html' })
m.add_extra_info :to => 'main.html', :redirect => 'foo_redirect.html'
m.find_entries :in => '.', :ignore => Google::Gears::LocalServer::Manifest::LEADING_PERIOD

find_entries is the real meat here:

# Defaults to '.'
find_entries :ignore => Google::Gears::LocalServer::Manifest::LEADING_PERIOD

# Only capture HTML pages
find_entries :include => '\.html'

# Look in the resources subdirectory, but use the URL 'static'. This is useful if your directory on disk doesn't match your URLs
find_entries :in => 'resources', :root => 'static'

Once you have created the entries, you may want to add some metadata to a few of them. This is where add_extra_info comes in:

# Find the 'main.html' entry and add a redirect. You can also use a different :src or :ignore_query.
add_extra_info :to => 'main.html', :redirect => 'foo_redirect.html'

You can also create a manifest object (instead of using the block version) if you need to add a few things, get the output, add a few more, etc etc.

If you find yourself not wanting to manage your Manifest file, check out the project.

One Response to “Google Gears Manifest Generator”

  1. Mark Holton Says:

    …very cool… makes me want to wrestle away more time to get my hands dirty with Gears. Thanks for the info.

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)