Learn how to make a site usable offline through an HTML 5 cache manifest. This first part of the series covers rack-offline and problems you may run into.
The cache-busting timestamps on asset files are there for a reason. What are the consequences for the rest of your app when you just get rid of them like this?
Nice one! I'd also be interested in learning a technique to handle updates done offline. I e offline/online syncing.
Also, I was thinking about a way to force the manifest to reload. How about adding a field to the user model (assuming we're working on a multi user app) called manifest_version. Then for each create/update or destroy this version is increased. Further a new view is created that simply renders this version. The path to this view is then added to the application.manifest. Upon reloading the manifest the browser should then notice a change in the manifest and the new manifest would be loaded. Am I making any sense here? :)
Ryan, you definitely read my mind, I was actually implementing a proof of concept of an offline app using HTML5 manifest and Web SQL database, that will definitely helps ! thank you so much, keep up the good work
P.S. : will part 2 talk about Web SQL database ? :)
Like Roberto Ruiz, I'm wondering if the issue raised with the manifest file not being invalidated after the database is updated, could not be handled by a sort of cache.
When the database stage changes, we want the application to issue a new manifest file, with a new ID within.
I'm sorry, but I'm missing the point of accessing a single page offline when you cannot actually use the app (ie, add records, see the changes etc). The real deal would be using the app with all bells and whistles via offline database and sync it when connection comes back.
Metin, I totally agree with your definition of an "offline application", but remember that's a "part 1".
Moreover, it's good to be able to use the application to build up your grocery list while connected (at home, for example) then bring it to the supermarket with you while not connected.
What a cliff hanger! I can't wait to see part II of this series.
I think offline apps might be really interesting when paired with single site browsers. Right now users don't expect web pages to do anything when they're offline. But if you have an app that is actually just a single site browser then the user expects functionality even when offline. It would also make packaging and distribution easy- an optimized experience for mobile Safari with a webkit SSB and an optimized experience for Windows desktops with an internet explorer SSB.
Fantastic screencast! Along with Part 2 these two are really fantastic, just like the rest of your stuff.
I am having an issue though. Has anybody had any problems with this railscast on Firefox? Safari works quite well but Firefox on the Mac does not seem to download the manifest after making 5 attempts to do so. So the webpage/application is not available offline in Firefox.
This is a great tutorial, however I'm having trouble getting it to work on my app. It seems like the instructions indicate the application.manifest file will auto-generate when you run localhost/application.manifest, but it doesn't do that for me :(
The app is Rails 2.3.8, Ruby 1.8.7 so I can't use Bundler to install, is that the problem?
I downloaded the code for the app and I'm having trouble trying to run it in Win 7 (FireFox and Chrome).
The app runs only if the server is running, otherwise I ger an "Unable to Connect". I'm running Rails 3.0.3 and ruby 1.9.2p0.
Thanks for the write up. I find that the rack-offline gem is good, but doesn't really fit my needs. I want the complete app to be available offline for a certain user (including all the users assets - thumbnails - saved with paperclip).
I've created a CacheManifest controller and model which loads a manifest with CacheManifestItems (another model) for each logged in user. If the user changes one of its files, the manifest get's updated the next time the user loads a page.
This works great: the entire app is available offline.
Also: writing your own controller action for generating the manifest file, makes it possible to generate a list of all the possible html-files the user may wish to see offline:
people/1
people/4
people/5
I'm happy with this solution. But I guess it won't be possible doing this if each user has a pretty big collection of records and files.
Currently Rack-Offline is broken for Chrome and Firefox. This is based around how it generates the hash in deployment. It is solved in this branch https://github.com/arsduo/rack-offline
Running rails 3.1.3 with rack-offline 0.6.2 and i lose the stylesheet everytime on refresh. My stylesheet names are in tact as I'm able to disable the timestamp hash that gets appended in the video. i tried the arsduo rack-offline fork to no avail. I know this video is a little older, any updates to know about for newer versions of Rails?
I have a problem, I cannot start server when using gem
This errors:
ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/routing/mapper.rb:191:in normalize_conditions!': You should not use thematchmethod in your router without specifying an HTTP method. (RuntimeError)
If you want to expose your action to both GET and POST, addvia: [:get, :post]option.
If you want to expose your action to GET, useget` in the router:
Instead of: match "controller#action"
Do: get "controller#action"
Hello Ryan, thanks for another excellent Railscast.
One question, the problem at the end can`t be addressed with a cache sweeper?
The cache-busting timestamps on asset files are there for a reason. What are the consequences for the rest of your app when you just get rid of them like this?
Nice one! I'd also be interested in learning a technique to handle updates done offline. I e offline/online syncing.
Also, I was thinking about a way to force the manifest to reload. How about adding a field to the user model (assuming we're working on a multi user app) called manifest_version. Then for each create/update or destroy this version is increased. Further a new view is created that simply renders this version. The path to this view is then added to the application.manifest. Upon reloading the manifest the browser should then notice a change in the manifest and the new manifest would be loaded. Am I making any sense here? :)
Ryan, you definitely read my mind, I was actually implementing a proof of concept of an offline app using HTML5 manifest and Web SQL database, that will definitely helps ! thank you so much, keep up the good work
P.S. : will part 2 talk about Web SQL database ? :)
Hi Ryan,
This is a great episode. I'm looking forward to watching next part.
Could you do an episode for calling mysql stored procedure by ruby on rails?
I'm googling it. not get any good answers. :(
Thanks
Like Roberto Ruiz, I'm wondering if the issue raised with the manifest file not being invalidated after the database is updated, could not be handled by a sort of cache.
When the database stage changes, we want the application to issue a new manifest file, with a new ID within.
Is that possible or the problem is even bigger ?
I'm sorry, but I'm missing the point of accessing a single page offline when you cannot actually use the app (ie, add records, see the changes etc). The real deal would be using the app with all bells and whistles via offline database and sync it when connection comes back.
Metin, I totally agree with your definition of an "offline application", but remember that's a "part 1".
Moreover, it's good to be able to use the application to build up your grocery list while connected (at home, for example) then bring it to the supermarket with you while not connected.
What a cliff hanger! I can't wait to see part II of this series.
I think offline apps might be really interesting when paired with single site browsers. Right now users don't expect web pages to do anything when they're offline. But if you have an app that is actually just a single site browser then the user expects functionality even when offline. It would also make packaging and distribution easy- an optimized experience for mobile Safari with a webkit SSB and an optimized experience for Windows desktops with an internet explorer SSB.
Thanks for the great video.
Fantastic screencast! Along with Part 2 these two are really fantastic, just like the rest of your stuff.
I am having an issue though. Has anybody had any problems with this railscast on Firefox? Safari works quite well but Firefox on the Mac does not seem to download the manifest after making 5 attempts to do so. So the webpage/application is not available offline in Firefox.
This is a great tutorial, however I'm having trouble getting it to work on my app. It seems like the instructions indicate the application.manifest file will auto-generate when you run localhost/application.manifest, but it doesn't do that for me :(
The app is Rails 2.3.8, Ruby 1.8.7 so I can't use Bundler to install, is that the problem?
I downloaded the code for the app and I'm having trouble trying to run it in Win 7 (FireFox and Chrome).
The app runs only if the server is running, otherwise I ger an "Unable to Connect". I'm running Rails 3.0.3 and ruby 1.9.2p0.
Thanks for the write up. I find that the rack-offline gem is good, but doesn't really fit my needs. I want the complete app to be available offline for a certain user (including all the users assets - thumbnails - saved with paperclip).
I've created a CacheManifest controller and model which loads a manifest with CacheManifestItems (another model) for each logged in user. If the user changes one of its files, the manifest get's updated the next time the user loads a page.
This works great: the entire app is available offline.
Also: writing your own controller action for generating the manifest file, makes it possible to generate a list of all the possible html-files the user may wish to see offline:
people/1
people/4
people/5
I'm happy with this solution. But I guess it won't be possible doing this if each user has a pretty big collection of records and files.
Currently Rack-Offline is broken for Chrome and Firefox. This is based around how it generates the hash in deployment. It is solved in this branch https://github.com/arsduo/rack-offline
Running rails 3.1.3 with rack-offline 0.6.2 and i lose the stylesheet everytime on refresh. My stylesheet names are in tact as I'm able to disable the timestamp hash that gets appended in the video. i tried the arsduo rack-offline fork to no avail. I know this video is a little older, any updates to know about for newer versions of Rails?
Any luck with that? I am now also trying with Rails 3.1 and rack-offline 0.6.4 and also lose the css & js on development
I have a problem, I cannot start server when using gem
This errors:
ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/routing/mapper.rb:191:in
normalize_conditions!': You should not use the
matchmethod in your router without specifying an HTTP method. (RuntimeError)
via: [:get, :post]If you want to expose your action to both GET and POST, add
option.
get` in the router:If you want to expose your action to GET, use
Instead of: match "controller#action"
Do: get "controller#action"
Thank for help!
Instead of: match "controller#action"
Do: get "controller#action"
Can I use this gem with rails 4?