Search code examples
ruby-on-railshtmlherokuasset-pipelineoffline-caching

HTML5 Offline feature doesn't work on Heroku server though It runs perfectly on dev machine


Here is the related source code:

offline = Rack::Offline.configure :cache_interval => 120 do      
 Rails.application.assets.each_logical_path.select{|e| not e.include? ".pdf"}.
    each {|e| cache "assets/" + e}
 network "/"  
end   
match "/application.manifest" => offline

Generated manifest seems fine, assets too, but it will stop downloading/caching assets in a random step with this message on Chrome: https://muster-apotheke.splettville.com/application.manifest

Appreciate any help.


Solution

  • By using the asset_path helper method, I can refer to production assets in cache manifest:

      if Rails.env.production?
        offline = Rack::Offline.configure :cache_interval => 120 do      
          cache ActionController::Base.helpers.asset_path("application.css")
          cache ActionController::Base.helpers.asset_path("application.js")
          network "/"  
        end
        match "/application.manifest" => offline  
      else
        offline = Rack::Offline.configure :cache_interval => 120 do      
          Rails.application.assets.each_logical_path.select{|e| not e.include? ".pdf"}.each {|e| cache "assets/" + e}
          network "/"  
        end    
        match "/application.manifest" => offline  
      end