2

I am trying to setup rack-offline in Sinatra, but I am having trouble setting it up. In rails it is prettty easy, but have no found any examples in Sinatra...

1 Answers1

1

Basically, in your config.ru, map /application.manifest to Rack::Offline. (If you're not familiar with using config.ru with your Sinatra application, check out this part of Sinatra docs.) Here's an example, which caches all the files under directory public:

require 'your-app'
require 'rack/offline'

map "/application.manifest" do
  offline = Rack::Offline.new :cache => true, :root => "public" do
    # Cache all files under the directory public
    Dir[File.join(settings.public, "**/*")].each do |file|
      cache file.sub(File.join(settings.public, ""), "")
    end

    # All other files should be downloaded
    network '/'
  end

  run offline
end

map "/" do
  run Sinatra::Application
end

Remember to set manifest="/application.manifest" in your html tag and you should be good to go. You should take a look at rack-offline's README for more documentation and explanation of how it works.

Miikka
  • 4,573
  • 34
  • 47