Created
          January 30, 2011 01:54 
        
      - 
      
- 
        Save mgutz/802424 to your computer and use it in GitHub Desktop. 
    jquery-tmpl slow compared to string substitution
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | head.ready -> | |
| # create 10,000 messages | |
| s = '' | |
| messages = [] | |
| for i in [0...10000] | |
| messages.push from: 'me', text: "blah blah" | |
| #//// jquery-tmpl | |
| $.template 'chatTemplate', | |
| """ | |
| {{each messages}} | |
| <li> | |
| <div class='from'> | |
| ${from} | |
| </div> | |
| <div class='text'> | |
| ${text} | |
| </div> | |
| </li> | |
| {{/each}} | |
| """ | |
| out = $.tmpl('chatTemplate', messages: messages) | |
| $(out).appendTo 'ul' | |
| #//// Same Using String with Proper HTML escaping | |
| h = (s) -> | |
| s.replace(/&/g,'&'). | |
| replace(/>/g,'>'). | |
| replace(/</g,'<'). | |
| replace(/"/g,'"') | |
| for msg in messages | |
| s += | |
| """ | |
| <li> | |
| <div class='from'> | |
| #{h msg.from} | |
| </div> | |
| <div class='text'> | |
| #{h msg.text} | |
| </div> | |
| </li> | |
| """ | |
| $(s).appendTo 'ul' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment