向 Rails 3.1 应用程序添加 HTML5 离线支持
我想为我的 Rails 3.1 应用程序添加 HTML5 离线支持,并且我遇到了 rack-offline,适合此目的的宝石。但是,rack-offline 仅将 public
文件夹中的资源添加到应用程序缓存清单文件中。如何让它还添加我的 assets
文件夹中的所有已编译资源(资源管道生成的资源)?
具体来说,我的 routes.rb
文件中有以下内容:
offline = Rack::Offline.configure do
cache "images/masthead.png"
public_path = Rails.public_path
Dir[public_path.join("javascripts/*.js")].each do |file|
cache file.relative_path_from(public_path)
end
network "/"
end
与我拥有 Rails.public_path
一样,我可以获得已编译资源的路径吗?这样我就可以使用上面的代码将该路径中的文件添加到缓存清单中。
I want to add HTML5 offline support for my Rails 3.1 app, and I've come across rack-offline, a gem suited for this purpose. However, rack-offline only adds the assets in the public
folder to the application cache manifest file. How do I have it also add all the compiled assets from my assets
folder (the ones that the asset pipeline generates)?
Specifically, I have the following in my routes.rb
file:
offline = Rack::Offline.configure do
cache "images/masthead.png"
public_path = Rails.public_path
Dir[public_path.join("javascripts/*.js")].each do |file|
cache file.relative_path_from(public_path)
end
network "/"
end
The same way that I have the Rails.public_path
, can I get a path to the compiled assets? That way I can use the above code to add the files in that path to the cache manifest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我相信这段代码应该放在初始化程序中,因为它只是配置:
要回答有关提供编译资产的问题,它们可以从浏览器访问,因此您需要做的就是手动提供缓存语句一切都应该正常。尝试使用这样的配置:
Well first things first, I believe this bit of code should be place inside an initializer since it is just configuration:
To answer your question about serving your compiled assets they are accessible from the browser so all you need to do is provide a cache statement manually and things should work. Try using a configuration like this:
我遇到了类似的问题,并编写了一个 gem 来解决资产 MD5 指纹问题。
https://rubygems.org/gems/assets_offline
I had a similar issue and wrote a gem to solve the assets MD5 fingerprint problem.
https://rubygems.org/gems/assets_offline