简体   繁体   English

PHP Dom解析器或Jquery加载?

[英]PHP Dom parser or Jquery load?

I want to load in a page a div from an another internal page. 我想在页面中从另一个内部页面加载div。 The div that i want to display is a cart. 我要显示的div是购物车。 I want to show the cart from my shopping website in the header of my blog. 我想在我的博客标题中显示来自购物网站的购物车。

I can use PHP Dom parser or Jquery load. 我可以使用PHP Dom解析器或Jquery加载。

Which solution is the best (performance, speed to display the content)? 哪种解决方案是最好的(性能,显示内容的速度)?

If you're concerned about speed, reduce the number of remote calls you have in your application. 如果您担心速度,请减少应用程序中的远程呼叫数量。 I write this especially because of this sentence in your question: 我之所以这样写,是因为您的问题中的这句话:

I want to load in a page a div from an another internal page. 我想在页面中从另一个内部页面加载div。

You should not do a remote call here to obtain the scripts output but instead - as long as it's your code generating that internal page - invoke the code instead directly that generates the HTML. 您不应该在这里进行远程调用来获取脚本输出,而是-只要是生成内部页面的代码-而是直接调用生成HTML的代码。

Example: 例:

  • Call magneto subroutines to generate the div , as it's a framework you might be able to create a route for that. 调用magneto子例程以生成div ,因为它是一个框架,您可能可以为此创建路由。
  • Create a template function inside your wordpress theme like the_basket that is outputting that chunk of HTML. 在诸如the_basket类的wordpress主题内创建一个模板函数,以输出该HTML块。
  • Use that function within your wordpress theme where the shopping cart should be displayed. 在应显示购物车的wordpress主题内使用该功能。

Next to that display performance in a browser is always best, when you provide all HTML before displaying. 当您在显示之前提供所有HTML时,在浏览器上的显示性能始终是最好的。 That is, if the <div> is already part of the page when the browser downloads it from the server. 也就是说,如果<div>在浏览器从服务器下载页面时已经是页面的一部分。 That's also best network performance as there is no additional request as with ajax. 这也是最佳的网络性能,因为没有像ajax那样的额外请求。

This method even tops ajax in any case if javascript is disabled or not working. 如果禁用了javascript或不起作用,则此方法在任何情况下都可以使ajax处于最高位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM