vicodin vicodin - 6 months ago 25
HTML Question

Where to store js templates?

I have some HTML templates, I use them for generating some new elements with jQuery. For now, I keep them in the bottom of my page as

<script type="text/html" id="ID_to_refer_from_jQuery">...HTML code here...</script>
, but I think it's a bad way, so where I can store such templates?

Answer

Put them in another folder and call them in with AJAX. You don't want to have one huge file. Rather, leverage the organizational folder system to keep your project organized.

Example Folder Structure

/root
  index.html

  /templates
    navigation.html
    footer.html
    ... 

Loading Them In

$("header").load("templates/navigation.html");
Comments