Question

When declaring what files to be cached in appcache manifest is there any way of including files that comes with dynamic names?

Such as the assets that are being compiled by rails.

assets/application-12315123213123151asd.js

In this case I would like to do something like this,

MANIFEST

CACHE
/assets/*.js

or

MANIFEST

CACHE
/assets/application-*.js
Was it helpful?

Solution

I made my own rake task instead of using gems such as rack-offline which doesn't seem to be updated in a long time.

#encoding: utf-8
desc "Create html5 appcache manifest"
task :html5_manifest => :environment do
    File.open("public/offline.appcache", "w") do |f|
        f.write("CACHE MANIFEST\n")
        f.write("# #{Time.now.to_i}\n")
        assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
        assets.each do |file|
            if File.extname(file) != '.gz'
                f.write("assets/#{File.basename(file)}\n")
            end
        end
        # f.write("NETWORK\n")
        # f.write("*\n")
        # f.write("FALLBACK:\n")
        # f.write("...")
    end
end

Put this as a task in your cap file when deploying to a server

OTHER TIPS

I know this thread is pretty old, but why not make a route to a Rails controller that serves the file and puts it together dynamically? Much like the rake task but it doesn't need to be generated when it's deployed. That would solve the Heroku problem...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top