For jQuery mobile, render markup client-side or transfer over the wire?
For a jQuery mobile app or website is 开发者_Python百科it better (in terms of speed, failover such as JS support etc.) to render the HTML markup client-side using Javascript? Or send it all over the wire?
I am asking specifically for the fixed UI markup (such as the navigation bar, header, footer, page divs and structure). Data rendering (lists etc.) will of course need to be re-rendered. And of course, it's possible to store the fixed UI markup in localstorage after rendering once.
For example, I could send the UI as
var UI = [{page_name: "page1", header : [<stuff describing header>], footer: [<stuff describing footer>]}]
I could use something like Mustache to turn this into <div data-role='page'>...</div>
and cache it. Is this a good idea?
Based on your description it seems like it would be best to send html down and let the browser cache it (assuming it really is fixed). I've never used Mustache though.
I've decided to go with the former: transferring UI description as a JSON object and translating it. This also allows me to store UI state information in the description object (like what page am I on inside this menu item).
精彩评论