Rack-Offline for Mobile HTML5 cached App with Rails 3.1 Asset-Pipeline

vor more than one year

When you delve into setting up your rails application.manifest for caching your iPhone mobile HTML5 app in offline modus you will stumble upon rack-offline from wycats. A great tool. Here are some tipps for getting this up and running with rails 3.1 and the asset pipeline - quickly.

In your routes.rb file you put in a block and syntax like this:

Yourapp::Application.routes.draw do  
offline = Rack::Offline.configure do  
   cache "index.html"  
   cache "assets/mobile.css"  
   cache "assets/background.png"  
   cache "assets/mobile.js"  
   network "/"  
end   
match "/application.manifest" => offline  

I like to explicitly list all the files that I am loading for the offline cache . This forces me to ensure brevity (as in the number of files to load) and to use the rails asset pipeline to concatinate all relevant files: Try to serve only one CSS and one .JS file for your mobile UI.

In your application.html.erb (or whatever file you serve as a mobile starting page) you extend the HTML tag:

<html manifest ="/application.manifest">

The rack-offline gem was released before all this rails 3.1 asset pipeline beauty. It was featured in Episode 248 of Railscasts: Offline Apps.

If you are on Rails 3.1 you are probably going wild with sass & scss and coffeescript and love the flexible syntax. So an extra step to compile your app for offline caching for a mobile html5 app can be quite a pain. You will want a setup where you can set this up once and more or less forget about it. In production the offline app caching should always be working but in development you will want to see the changes to your code without switching on and off the application.manifest all the time. I found that the rack-offline gem docs were not so clear how to set it up, and tore my hair outs for half an hour.

Mind you - in my first mobile app I had an extremely funky workflow to deal with the offline cache and revisions.

Hope this saves you some time. Also watch Ryan Bates Screencast - It will give you insights into some of the gotchas you might encounter when working with offline caching.

Author: Roland Oth. Ich bin zu finden auf Twitter als @smtm, und als roland.oth auf Facebook

Jetzt unverbindlich igumbi probieren:

igumbi Hotelsoftware Demo System Übersicht

igumbi, ist eine online Hotelsoftware mit einem einfachen und schnellen Buchungstool für Ihre Website.

Wir steigern zusammen Ihre provisionsfreien Direktbuchungen. Sie sparen Zeit und haben Sie Ihre Daten immer im Zugriff.

 Demo ansehen

Tags: rails mobile offline html5