• Hello!

    Will variables added with wp_localize_script be cached? I need to pass some user specific data to a javascript-file, and I don’t want it cached between sessions. Is there another way besides AJAX?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Do you mean cached by the browser? Or server side caching? Server side, it depends on the caching scheme, but there ought to be a way to exclude specific pages. For browser caching, sending a Cache-Control header with appropriate value should prevent caching. The “send_headers” filter can be used to alter what headers WP sends.

    Or you could get the user specific data as part of the Ajax response instead of passing it through wp_localize_script().

    Thread Starter Dekadinious

    (@dekadinious)

    I would think server side caching is the most relevant. I am basically trying to integrate the Snapchat Pixel in a smart and minimal way. Snapchat wants user email and phone number when they are logged in, and they want it on every page load. So I am using wp_localize_script to avoid AJAX-calls for every page load. I don’t know if that’s necessary to avoid or not?

    I am looking through the official Facebook Pixel for WordPress plugin to find some hits as to how they do it. I see that they also print JavaScript to the page with my email and phone number. This JavaScript is not present in incognito, and I would assume that the values are different for different people.

    I see they use wc_enqueue_js some places, but I haven’t quite been able to track how they deal with caching etc. I can’t see that they use any AJAX-calls to get that information.

    So the question is really: How do I give a JavaScript-file or the browser dynamic sensitive info that should not be cached between users? And how to I do it in a resource sparing way?

    Thread Starter Dekadinious

    (@dekadinious)

    Answer: Hash it and throw it in a cookie ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_localize_script and caching’ is closed to new replies.