开发者

Making Mongrel/WEBRick serve static assets with future expires header

I'm creating a Rails application which will be deployed to desktop machin开发者_Python百科es, running both the webserver and the browser (it's a test-taking application which needs to be able to run without an internet connection).

For this reason, I'll be running Mongrel or WEBRick, without an Apache/Nginx in front of it as you would normally do. The browser will access the Mongrel directly.

The problem I'm facing now is that it takes a while to load assets (javascript/stylesheets/images). Normally, I'd fix this by setting future expiry dates on these assets in the Apache proxy in front of the Mongrel/WEBRick, so that the assets are only requested once, and after that there is only one request per action.

But in this case, there is no proxy, and i'm using config.serve_static_assets = true

So the question is: is it possible to tell Mongrel/WEBrick to slap far-future expiry headers on the static assets?

I'm using Rails 3 on Ruby 1.9.2.


you can try something like this :

   def get(path)
     @headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain"
     unless path.include? ".." # prevent directory traversal attacks
       @headers['X-Sendfile'] = "#{PATH}/static/#{path}"
     else
       @status = 403 # "403 - Invalid path"
     end
   end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜