Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Challenge offline apps on Rails 3.2

Challenge offline apps on Rails 3.2

Below articles depended on rails 3.0.3. I try to this on Rails 3.2.2.

rack-offline gem is not latest

  • rack-offline gem is v0.6.2 August 16, 2011. At github repos, after that this is fixed for rails3.1 or higher.
  • I can use Gemfile:
gem 'rack-offline', :git => 'git://github.com/wycats/rack-offline.git'

This is shown v0.6.1, but this is higher than v0.6.2(as v0.6.3).

assets pipeline

  offline = Rack::Offline.configure do
    cache "assets/application.js"
    cache "assets/application.css"
    files = Dir[
      "#{root}/**/*.html"]
    files.each do |file|
      public_dir = Pathname.new("#{root}/public")
      cache Pathname.new(file).relative_path_from(public_dir)
    end
    files = Dir[
      "#{root}/assets/**/*.{js,css,jpg,png,gif}"]
    files.each do |file|
      cache Pathname.new(file).relative_path_from(root)
    end

    network "/"
  end
  match "/application.manifest" => offline

Write cache manifest mapping is too hard

app/assets/javascripts/application.js #=> assets/application.js
app/assets/javascripts/items.js.coffee #=> assets/items.js
vendor/assets/javascripts/foo.js.erb #=> assets/foo.js
rubygems ;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment