What are the best practices for including dynamic content generated by PHP in a JavaScript script for client-side rendering?

When including dynamic content generated by PHP in a JavaScript script for client-side rendering, it is best practice to use AJAX to fetch the dynamic content asynchronously. This ensures that the JavaScript code can interact with the PHP script without reloading the entire page. By using AJAX, you can update specific parts of the page with the dynamic content without disrupting the user experience.

<?php
// PHP script to fetch dynamic content
$dynamic_content = "This is dynamic content generated by PHP";
echo json_encode($dynamic_content);
?>