最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What are the advantagesdisadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?

programmeradmin2浏览0评论

I'm working on a plugin that takes $content for a post and alters some of the HTML. Seems there are two common ways to accomplish this in WordPress - using jQuery or using PHP's DOMDocument. I'm wondering what the advantages/disadvantages of one over the other are?

I'm working on a plugin that takes $content for a post and alters some of the HTML. Seems there are two common ways to accomplish this in WordPress - using jQuery or using PHP's DOMDocument. I'm wondering what the advantages/disadvantages of one over the other are?

Share Improve this question asked Nov 3, 2019 at 14:47 davemackeydavemackey 3152 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

PHP is running on the server, JavaScript in the client.

This means PHP is faster (more resources), the result can be cached, and you have to test only one interpreter.

JavaScript – you don't really need jQuery for this – is more error prone, because of weird clients, blocked resources, or a more limited available memory. However it can respond to user input immediately without an extra page load.

If you have a situation in which both ways are leading to the same result, go for the server side.

发布评论

评论列表(0)

  1. 暂无评论