Search code examples
jqueryruby-on-railsjsrender

JSrender produces a different result depending on Rails environment?


I am using JSrender on the front-end of my Rails website to generate lists of items, for example. On localhost, in development, running something like (with 'data' being an array of objects):

template.render(data)

Will produce a string of HTML with newlines on every element, and a double newline between list items. Running jQuery on this in development gets something like:

[ li, text, li, text, li, text ]

With 'text' containing empty lines.

However, when I run this same code on our production environment, it will produce minified HTML, with no new lines in the string, so my jQuery array looks like:

[ li, li, li ]

Is this a setting of JSrender I can manually enable/disable? How does my Rails environment affect a library that is served statically to the front-end? Or is something else going on? Thanks


Solution

  • I've figured out why. Production HTML is minified, and I use a template from the page to generate new HTML in JsRender. So it is just taking HTML that is already minified and producing more of it, whereas in development the HTML page isn't minified.

    Thanks @BorisMoore for confirming JsRender doesn't have a setting that affects newlines.