wycats / rack-offline

A Rack and Rails plugin for building offline web applications
MIT License
666 stars 82 forks source link

Getting uncached mode to work #10

Closed arsduo closed 13 years ago

arsduo commented 13 years ago

Right now, Rack::Offline offers an uncached mode in which the manifest is constantly regenerated; it's a great idea for development (and is on by default in dev environment), but doesn't actually work. The problem is that the cache-breaking comment in the manifest is generated by the following line:

Digest::SHA2.hexdigest(Time.now.to_s + Time.now.usec.to_s)

Since the browser downloads the cache twice (once at the beginning, and once at the end for verification), the use of usec means the manifest will always be different and the app cache can never be built.

I've written a patch (with tests) to change this behavior; with these changes, the comment will only change after a configurable interval (by default 10 seconds) to allow the browser to download the cache first. (There's always a risk that the download will start too close to the boundary, but since this is development only, the developer can adjust the interval to his or her preference.)

PS thanks for the very useful gem! I remember hearing about it in a side talk at the jQuery conference last year in Mountain View, and am very excited to finally be using it.

tosswill commented 13 years ago

works for me.