Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using templates in javascript instead of server side

Posted on 2016-09-13
2
Medium Priority
?
58 Views
Last Modified: 2016-09-28
HI,
In my js code currently i have the following :
var htmlstring = $.parseHTML(htmlstring);
   $('body').append(htmlstring
This html string is created on server side from an html template... and looping over a list.

I wonder what are the performance issues this could cause if the html string i huge : $.parseHTML(htmlstring)
Other way i can think of is return an array of json objects.. And then create DOM on client side...
Dont know if creating a template on client side is possible ?
Also will that be easy for browser ?

pointifying some things :
1) There is an ajax call from client which returns an htmlString
This htmlString is created from a list and an html template
2) Performance isues with $.parseHTML(htmlstring)
3) How do i do the same thing by returning the json and creating html on client side.. some way so that browser does not probably have to create any DOM as template structure is already there.

Here is the template i am using on server side :
<div th:each="testList : ${testList}" class="test"
     th:attr="data-id=${testList.id},data-chat-id=${testList.conversationId},data-show-all=${showAll}">
  <div class="caption">
    <span th:if="${showAll} == true" th:text="'In: '+${testList.chatName}"/>
    <span th:if="${showAll} == false" th:text="${testList.userName}"/>
    <span th:text="${testList.date}"/>
  </div>
  <h3 th:text="${testList.title}"/>
  <div class="xyz"
       th:utext="${testList.preview}"/>
</div>

Open in new window


Thanks
0
Comment
Question by:Rohit Bajaj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 41797164
Check this page : https://docs.angularjs.org/tutorial/step_02
Welcome to angular.
In the example you can see we use this :
    <li ng-repeat="phone in phones">
      <span>{{phone.name}}</span>
      <p>{{phone.snippet}}</p>
    </li>

Open in new window

and this json :
  $scope.phones = [
    {
      name: 'Nexus S',
      snippet: 'Fast just got faster with Nexus S.'
    }, {
      name: 'Motorola XOOM™ with Wi-Fi',
      snippet: 'The Next, Next Generation tablet.'
    }, {
      name: 'MOTOROLA XOOM™',
      snippet: 'The Next, Next Generation tablet.'
    }
  ];

Open in new window

to create a nice list
0
 
LVL 82

Expert Comment

by:leakim971
ID: 41819746
do you need more ? did I miss something ?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
A solution for Fortify Path Manipulation.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question