PHP vs JavaScript For Dynamic HTML Pages

后端 未结 6 709
南方客
南方客 2020-12-13 10:15

Typically when I put together dynamically generated HTML markup, I\'ve been using PHP to store the information and then looping through that to create elements on the page.

6条回答
  •  暖寄归人
    2020-12-13 10:18

    One possibility would be to detect what kind of user is viewing your site :

    • If it's a bot: parse on the server-side, you may just output what is needed by the bot, without graphical things,...

    • If it's a mobile : show a mobile optimized version, using something like Sencha Touch, as Charlie pointed out

    • If it's a standard browser, without javascript : render the page on the server side

    • If it's a standard browser, with javascript enables : just send the data from server side (or load it with Ajax) and render the data from the client-side

    You may use something like Mustache, wich is a template engine running on many server-side languages (PHP, Ruby, Java,... but also on Javascript, enabling client-side page rendering!

    And try to use a Javascript framework like jQuery, Mootools, Dojo or ExtJS, they will help you to write code that will run on every browser.

提交回复
热议问题