wp_localize_script and host/browser cache

The data passed by wp_localize_script() is output in a <script> tag in the page HTML. So if you have this:

wp_localize_script( 'registered_script', 'serverData', array( 'posts' => $post_array ) );

This will be on the page:

<script type="text/javascript">
    /* <![CDATA[ */
    var serverData = { "posts": [] };
    /* ]]> */
</script>

This means that if your page HTML is cached with something like WP Super Cache or WP Rocket this data will also be cached. So if you need the data to be 100% up to date, to the second, then you should retrieve fresh data via AJAX in your script.

Keep in mind that wp_localize_script() was originally designed to provide localized/translated strings to scripts, and those don’t need to be updated anywhere near that frequently.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)