Posts match “ rails ” tag:

Revised Batman.js all-views-cache hack

Batman.js works very well with Rails. However, when it comes to production environment, the way Batman request every view template via Ajax on demand will cause some inconvenience.

John Lynch and Ryan Funduk has an post about how to precompile all view templates into one json, and fetch it on App runs. This solves most issues, but has one drawback. When you're about to load the all-views json file, your App has actually became running already. It will look for the template of your root (or firtly-requested) view, and will be unable to find it in View Cache 'cause the Ajax is still running.

Eventually, Batman.js will try to download the view template almost at the same time your precompiled all-views json starts to be fetched. And this will generate one more HTTP request, and may occur some 404 errors if those template files are not served on the server.

Here's how I try to revise this hack and solve the above issue: prevent the Batman.App from running until the view caches are successfully loaded.

Read on