Title: wp_localize_script and caching
Last modified: November 19, 2020

---

# wp_localize_script and caching

 *  [Dekadinious](https://wordpress.org/support/users/dekadinious/)
 * (@dekadinious)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/wp_localize_script-and-caching/)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/wp_localize_script-and-caching/#post-13684816)
 * 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](https://wordpress.org/support/users/dekadinious/)
 * (@dekadinious)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/wp_localize_script-and-caching/#post-13686190)
 * 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](https://wordpress.org/support/users/dekadinious/)
 * (@dekadinious)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/wp_localize_script-and-caching/#post-13693796)
 * 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.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [Dekadinious](https://wordpress.org/support/users/dekadinious/)
 * Last activity: [5 years, 6 months ago](https://wordpress.org/support/topic/wp_localize_script-and-caching/#post-13693796)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
