custom post types - localize_script or rest api

If the data is available in both options, in what use cases should i use the localize script to make data available to m

If the data is available in both options, in what use cases should i use the localize script to make data available to my javascript code, and in what cases should i use the rest_api?

I have a custom post type that has meta data which needs to be passed to my php code. I have the option to localize my script and use the data directly, or to call the rest-api and pull the information through ajax.

Which of these two is considered best practice/ which would you advise to use? Or should i use both (to authenticate the api call?) ?

If the data is available in both options, in what use cases should i use the localize script to make data available to my javascript code, and in what cases should i use the rest_api?

I have a custom post type that has meta data which needs to be passed to my php code. I have the option to localize my script and use the data directly, or to call the rest-api and pull the information through ajax.

Which of these two is considered best practice/ which would you advise to use? Or should i use both (to authenticate the api call?) ?

Share Improve this question asked Jul 23, 2019 at 10:35 fogxfogx 1011 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

You'd only use the REST API or AJAX if you didn't know what data you needed until the script was run or there was some user interaction. If you already know the data you need based on page you're on then you might as just pass that data with wp_localize_script(), otherwise you're forcing the client to make a separate request once the page has loaded, slowing everything down.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745302705a4621533.html

相关推荐

  • custom post types - localize_script or rest api

    If the data is available in both options, in what use cases should i use the localize script to make data available to m

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信