How to load external jQuery templates

I have a large number of jQuery templates taking up space in my <head> section ("text / x-jquery-tmpl"). I would like to move these tags to an external file. I was hoping I could do something like <link href="/templates.html" type="section"/> , but I understand that it’s not what link it is for, and it really doesn’t work.

What is the best way to do this? I could look at the bootloader (it may be hard to find the html loader, though), but it seems like overkill. Maybe I have no choice but to add tags to my page.

+6
source share
2 answers

you can use the src attribute, for example:

 <script src="/my/templates.html" type="text/x-jquery-tmpl"></script> 
0
source

You can use a separate file for each template, and then use the jQuery download function and enter each template where you want to use it. For instance:

 $('body').load("templates/template1.html"); 
0
source

Source: https://habr.com/ru/post/889534/


All Articles