You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Apache Wiki <wi...@apache.org> on 2006/08/15 16:58:04 UTC

[Jakarta-velocity Wiki] Update of "VelocityFAQ" by NathanBubna

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-velocity Wiki" for change notification.

The following page has been changed by NathanBubna:
http://wiki.apache.org/jakarta-velocity/VelocityFAQ

The comment on the change is:
add entry about memory usage

------------------------------------------------------------------------------
  [[BR]]
   * Q: Why are Velocity templates not working from !JavaScript?
   * A: Velocity runs on the '''server''', whereas !JavaScript runs on the '''client''' in the browser. Examples: a user requests a page, on the server Velocity renders templates into HTML which is sent to the browser to display. All of the Velocity template processing happens '''before''' the page is sent to the browser. There is no way for !JavaScript to render Velocity template directives without going BACK to the server. Note also that Velocity '''can''' be used to render custom !JavaScript. (Tim Colson) 
+ [[BR]]
+  * Q: How can i lower memory usage by Velocity?
+  * A: If you have no concerns about speed, the easiest thing is to just turn off template caching. This can be done by setting {{{<resource loader name>.resource.loader.cache = false}}} (see [http://jakarta.apache.org/velocity/docs/developer-guide.html#Configuring%20Resource%20Loaders Configuring Resource Loaders]).  If you still want to maintain some level of caching, try upgrading to Velocity 1.5 which uses an LRUMap for template caching.  This allows you to limit caching to any specified number of your most used templates.  Just set {{{resource.manager.defaultcache.size=<some number>}}}.  It is also possible to create your own custom !ResourceCache and plug that in instead of the default cache.
  
+ If none of these tweaks work for you here are a few more tips:
+ 
+   - try rewriting a few velocimacros in java (the ones that are called most often)
+ 
+   - try rewriting a few pages, using loops instead of repeatedly calling velocimacros
+ 
+ Remember, Velocity doesn't compile your templates.  They are parsed into an AST (abstract syntax tree) and that is what gets cached.  So, reducing template complexity will shrink the tree and produce immediate memory savings.  For loops and (java) "tools" are simpler than velocimacros. (Nathan Bubna & Bruno Carle)
  
  === Velocity Tools ===
   * Q: The !MessageTool is throwing a !NullPointerException, why doesn't VelocityTools test for NPE's?
@@ -55, +65 @@

   * A: One possibility is that it might not be sharing a configuration with !VelocityViewServlet. More specifically, !VelocityViewServlet was previously based on a singleton Velocity class.  If you had other uses of Velocity within the same webapp that also used the singleton Velocity class, they would share configuration data.  Now !VelocityViewServlet uses a !VelocityEngine instance to process templates.  You can get this instance for other uses of velocity by calling get!VelocityEngine from a subclass.  Or, create and configure a second instance of !VelocityEngine.  (while slightly more involved, this allows different configuration options which are often desired).  (Will Glass-Husain) 
  [[BR]]
   * Q: VelocityTools doesn't work with Struts 1.2!
-  * A: For Struts 1.2, you need VelocityTools 1.2, which is still under development.  You can get nightly snapshots at http://cvs.apache.org/snapshots/velocity-tools/.
+  * A: For Struts 1.2, you need VelocityTools 1.2, which is now available for download.
  
  === DVSL & Anakia & Texen & Misc ===
   * Q: Is DVSL stable enough for use in production environment?

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org