toretore / babilu

ABANDONED - Use i18n-js instead
MIT License
65 stars 11 forks source link

locales.js generating multiple times in development environment causes javascript parse error #1

Open nathany opened 14 years ago

nathany commented 14 years ago

After struggling with a JavaScript parse error in locales.js for quite a while, I determined the cause. The error is a missing } even though the code looks/lints fine. It is a result of multiple near-simultaneous requests in development mode.

We have a route to a stylesheet action that pulls the CSS from a database. When a page is hit (in development), the generate_locale_javascript filter is fired once for the page and again when the page loads the stylesheet action. My assumption is that this results in a partially overwritten locales.js being returned, hence the parse error.

My solution for now is as follows: skip_after_filter :generate_locale_javascript, :only => :stylesheet

I'm submitting this so others are aware of the issue, and perhaps we can come up with a better solution in Babilu itself. Regenerating only if the yml files change should at least reduce, if not eliminate the issues.

Mange commented 14 years ago

On UNIX-like systems, the process doing the generation could lock the file. This would keep other forks from trying to write to it at the same time.