开发者

jquery plugin with tons of html

I'm working on a jQuery project right now that will essentially dump a bunch of HTML on someone's page when t开发者_JAVA百科hey incorporate our plugin.

This little widget has a decent amount of HTML.

So, is it best to put 150+ lines of HTML inside the plugin itself? I had a thought that was basically "have the plugin use jQuery's ajax to pull a chunk of HTML from our server, and then use THAT instead of putting a bunch of stuff inside the JS file", but not sure if that's the best approach, in terms of the overall jQuery plugin methodology.


If you need flexibility in your plugin, you should pull the HTML separately, as this will allow you to easily change out the text, and use the same plugin for different purposes.

If the text will never change, or changes infrequently, you might as well leave it in the plugin.


The plug-in shouldn't require that your server be active. If they are still using it 2 years from now, and you've moved on, they shouldn't suffer. It would definitely be better for the HTML to be contained in the plug-in, and save another round trip to another remote server. It will also save you bandwidth and resources when a potentially large number of sites use your plug-in.


  1. use jQuery.tmpl()
  2. fetch json data from server
  3. fetch templates from server
  4. populate jquery templates with json data

http://encosia.com/using-external-templates-with-jquery-templates/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜