2011-03-30 166 views

回答

1

基本上,在您的config.ru,地圖/application.manifestRack::Offline。 (如果你不熟悉使用config.ru與西納特拉的應用程序,看看this part of Sinatra docs)下面是一個例子,它可以緩存目錄下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 

記得設置manifest="/application.manifest"html標籤和你應該很好走。你應該看看rack-offline's README瞭解更多文檔和解釋它是如何工作的。