jQuery vs. PHP - Performance Comparison

后端 未结 8 809
猫巷女王i
猫巷女王i 2021-01-15 06:37

Performance-wise, which would be the better solution? Here\'s a really small example. The PHP script returns a number to jQuery, which needs to be checked if it\'s 1

8条回答
  •  灰色年华
    2021-01-15 06:54

    Assuming the number is coming from a resource within your OWN website (not some other website's value you're parsing): PHP would be faster.

    • No overhead (done at page execution)
    • Not awaiting page load event to then perform an AJAX query to then parse it out

    If this is a value from another page, I still believe PHP is faster (using cURL/fopen [if site allows it]/etc.). You're talking the difference of something running before the page is fed to the user versus pushing the load on to the user and waiting for their page to load first then populating the field.

    Realistically though, it just depends on how you want the user experience to be. Do you want it seamless or to load as little as possible and build on it as the page gets loaded?

提交回复
热议问题