PHP与JavaScript的动态HTML页面 [英] PHP vs JavaScript For Dynamic HTML Pages

查看:97
本文介绍了PHP与JavaScript的动态HTML页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当我将动态生成的HTML标记放在一起时,我一直使用PHP来存储信息,然后通过循环来在页面上创建元素。一个例子是导航;创建一个对象数组,然后遍历它们以回显标记。这在开发或维护过程中可能需要进行较小(或主要)更改的时候会有所帮助。



最近我一直在想我是否应该使用JavaScript代之以做到这一点。同样的原则,但使用addElement。



只是想获得一些意见,

谢谢大家!

解决方案 在做很多不同的环境而不是一个环境中做它
  • 无论用户何时出现JS(无论什么原因),它都会中断

  • 如果它无法适用于绝大多数机器人(包括搜索引擎) / li>
  • 在转换所有逻辑时投入开发时间
  • 要求浏览器向服务器发出额外请求,以减缓加载时间

  • 在决定是否应该在客户端而不是服务器端做一些事情时,作为一个经验法则问自己两个问题:


    1. 用户是否可以获得即时反馈,以响应他们做的事情?例如他们尝试提交的表单中的数据不正确的错误消息。如果是这样,那么做客户端将是有益的。

    2. 它可以在服务器端完成吗?如果是这样,首先做服务器端,因为它更可靠(并且非美化的东西,更难以干预)。 建立在工作之上的东西


    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. One example is navigation; create an array of objects and then loop through them to echo the markup. This helps out a lot for times that I might have to make minor (or major) changes during development or maintenance.

    Lately I've been wondering if I should use JavaScript to do this instead. Same principle, but using addElement.

    Just wanted to get some opinions on this; pros, cons, php vs js, seo considerations, etc.

    Thanks folks!

    解决方案

    Doing it client side means:

    1. Doing it in lots of different environments instead of a single one
    2. Having it break whenever a user comes along without JS (for whatever reason)
    3. Having it fail to work for the vast majority of bots (including search engines)
    4. Investing development time in converting all your logic
    5. Requiring the browser to make additional requests to the server, slowing down load times

    When deciding if you should do something client side instead of server side, as a rule of thumb ask yourself two questions:

    1. Would the user benefit from getting instant feedback in response to them doing something? e.g. An error message for improper data in a form they are trying to submit. If so, then doing it client side would be beneficial.
    2. Can it be done server side? If so, do it server side first as it is more reliable (and for non-cosmetic things, harder to interfere with). Build on things that work.

    这篇关于PHP与JavaScript的动态HTML页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆