Friday, June 14, 2013

FreeMarker: An open alternative to JSP

Today I read a good article about FreeMarker - an alternative to JSP: http://www.javaworld.com/jw-01-2001/jw-0119-freemarker.html?page=1

Some notes about performance which I were looking for:

- Much like JSP, FreeMarker compiles templates to improve runtime performance. Those templates are stored in memory in a format that leaves placeholders for dynamic data. The controller fills those placeholders with dynamic data from the model. For this purpose, the controller must have access to both the model and the view. Once the dynamic data is retrieved from the model, the controller will print the template to a given output stream.
- Once templates are compiled, you can process them in parallel, leading to a significant performance boost.

- For anything other than the most trivial projects, FreeMarker provides a TemplateCache interface, implementations of which act as a repository for precompiled templates.

- An additional feature of TemplateCache objects is that they automatically reload templates when the template source file has changed. That relieves you of having to start and stop the servlet engine when you need to make changes to the HTML.

JSP versus FreeMarker (official documentation): http://freemarker.sourceforge.net/docs/app_faq.html#faq_jsp_vs_freemarker

Wednesday, June 5, 2013

Debugging JavaScript in Chrome

Let's have test.html:

<html>
  <head>
   <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
   <script type="text/javascript" src="fun.js"></script>
  </head>
  <body>
   <button onclick="return simpleFunction();">Click me</button>
   <ul id="testId"></ul>
  </body>
</html>


and fun.js:

function simpleFunction() {
  for (var i=0; i < 7; i++) {
   var html = '<li>' + i + '</li>';
   $('#testId').append(html);
  }
  return false;
}