Moving to html offline : Part 1

I lately had a very educational chance to conclude a project which involved writing an offline HTML5 app, with a backend written in ruby on rails. I learnt a couple of lessons along the way, i’d love to know what the readers think, and maybe weigh in on a couple of the points that i’ll present over three short articles. The first article here will mention some rails specific javascript and turbolinks issues.

– move assets to Public Folder
Normally when writing rails apps, one places all java script and css files into the app/assets folder. This however has the disadvantage of not really giving you control over which of these assets are included with different pages. For example, including a .js file in the assets folder will include the js file in each and every html page visited by a client. This can prove to be a problem for offline apps, specifically because these tend to be single page apps with specific javascript included. Including this javascript in all your pages will probably result in unintended results. So, we moved the JavaScript into the Public folder to enable us to manually link to the js files and so regain more control.

This does come with a downside. Apart from having to link to the files manually (which can be offset by the use of partials), you also lose the advantage of automatic minimization. Keep in mind that once placed in the public folder you will have to manually minimize the JavaScript files.

– remove turbolinks
Turbo links is awesome but it essentially works by caching JavaScript links. We learnt that most of the time caching is your enemy in offline apps since JavaScript is your main way of navigating around the web app. Say a user clicks on a link with an attached java script listener that pulls content via Ajax to dynamically update the webapp. Turbolinks may get in the way of this since it will try to cache the results and serve them quicker to the user next time round. Generally, we found that as a rule we were better off disabling turboIinks.