Ecommerce Shopify WordPress Discussion

wp_add_inline_script vs wordpress fetch api [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 days ago. Improve this question Inorder to pass some data from PHP to the javascript files, we can use either wp_add_inline_script or fetch api. Is there any condition, where each one of them is preferred over the other ? I have used both but feeling some confusion. Suppose, if I have a plugin page, which shows a list of settings saved in option table. The page is rendered using React. So need to get the value for the settings from database in React files. So in this case, I can call get_option and pass them to my react (or javascript) file using wp_add_inline_script or make use of fetch api in the react useEffect hook. But I think wp_add_inline_script is better so I can reduce the fetch calls and may be the performance. So depending on security, performance and coding standards, is there any cases that should be considered while choosing between this two ? In my case, both of them are used to pass data from PHP to React.
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.