PHP vs JavaScript For Dynamic HTML Pages

后端 未结 6 713
南方客
南方客 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:35

    Best practice would be to produce any necessary markup on the server side. Reasons for this include:

    SEO: Most crawler bots won't parse Javascript, so they'll skip over anything crucial that you're generating with addElement.

    Accessibility: Your site should basically functional without Javascript. Consider people who might be browsing your site on Kindles, older Blackberries, Nokias or other feature phones with data. They don't need all the fancy styles and effects, but they should at least be able to get around your site.

    Consistency: JS can add yet another level of cross-browser variability. Why rely on client-side rendering of necessary markup? Do it server-side.

    Of course, this advice can be taken in stride if you're developing an all-JS desktop app or using something like the Sencha Touch framework.

提交回复
热议问题