Title: Autoptimize and Session Variables
Last modified: October 21, 2016

---

# Autoptimize and Session Variables

 *  Resolved [sasserp01](https://wordpress.org/support/users/sasserp01/)
 * (@sasserp01)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/)
 * Hello,
 * Always like to start off by saying love the plugin. I’ve got a site running WordPress
   and Autoptimize. The site uses WooCommerce and products are filtered by two store
   locations. The site uses session variables to set the location. If the session
   var is one location or another the main query is adjusted to include that location.
   Is there anyway to account for this using autoptimize? So essentially this URL
   product-category/arm-chair/ might show three different things 1) All the products
   in that category, 2) all the products in that category at location 1, and 3) 
   all the products in that category at location 2.
 * Thanks much for the help and support.

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8337351)
 * Hi sasserp01; AO “simply” aggregates JS/ CSS it finds in any page. if for the
   same page it gets different CSS/ JS, it simply creates a new version of the autoptimized
   code and continues with that. So at first thought this seems like an issue for
   a page caching plugin rather then for AO? Or am I missing something here?
 * frank
 *  Thread Starter [sasserp01](https://wordpress.org/support/users/sasserp01/)
 * (@sasserp01)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8341912)
 * Hey Frank,
 * Ahh okay. So Autoptimize …
 * 1) gets the page request
    2) aggregates JS/CSS on that page 3) compares that 
   compressed version of the page with what is cached 4) If a cached copy is “equal”
   to the page comparison then the cached page is served 4b) Otherwise the newly
   compressed version is cached and served
 * Am I correct here? So Something else must be caching these session variables.
   WP Super Cache is out there, but I could have sworn that I disabled caching for
   these particular pages.
 * Thanks much,
    patrick
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8341921)
 * almost; but in (3) AO compares the aggregated but not minified JS/ CSS with what
   is already in cache (based on an md5-hash) and in (4) the cached JS/CSS is served
   if the the cached file exists and in (4b) the file is saved as autoptimize_<md5hash-
   of-the-unminified-code>.js (or .css)
 * if not WPSC this is maybe some object cache?
 *  Thread Starter [sasserp01](https://wordpress.org/support/users/sasserp01/)
 * (@sasserp01)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8342099)
 * What do you mean by object cache? This is blowing my mind right now. If I’m logged
   into WP-Admin then the session variables work. If I’m not logged into WP-Admin
   then the session variables don’t work. WP-SuperCache adds in a comment at the
   bottom of the source code that tells you the page is cached by WP-SuperCache 
   and on the pages in question there is no comment. So They aren’t being cached
   by WP-SuperCache, unless there is some sort of residual cache (I’ve deleted cached
   like a million times). Any thoughts? I’ll keep digging
 * Thanks,
    patrick
 *  Thread Starter [sasserp01](https://wordpress.org/support/users/sasserp01/)
 * (@sasserp01)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8342118)
 * Ok I think I figured it out here is the code that I had going on…
 *     ```
       add_action ('pre_get_posts', 'woo_destroy_session' );
       function woo_destroy_session ($query) {
       	if(is_shop() || is_page( ) ) {
       		if ( is_session_started() === TRUE ) session_destroy();
       	}
       }
       ```
   
 * The session would be destroyed essentially if you leave the shop page. So you
   set a location session to filter items by and then when you go to a page or back
   to the main shop page that session is removed. However, strangely when you are
   logged into WP-Admin this if works as expected
 * `if(is_shop() || is_page( ) )`
 * and then when you log out it doesn’t work anymore as expected and it always returns
   true so the session is always deleted. Any ideas as to why this might be happening?
   More of a general WordPress question.
 * Thanks,
    patrick
    -  This reply was modified 9 years, 6 months ago by [sasserp01](https://wordpress.org/support/users/sasserp01/).
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8342361)
 * > The session would be destroyed essentially if you leave the shop page.
 * correct me if I’m wrong (I often am), but doesn’t this code destroy the session
   when you’re on a shop-page or a page and if a session exists?
 *  Thread Starter [sasserp01](https://wordpress.org/support/users/sasserp01/)
 * (@sasserp01)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8342534)
 * You’re right. I sort of misspoke. The session is supposed to be destroyed if 
   you’re on a page or if you’re on the main shop page. So if(is_shop() || is_page())
   should be what I’m looking for. Just not sure why it isn’t working.
 *  Plugin Author [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * (@futtta)
 * [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8342603)
 * hmmm .. out of my comfort zone here and not really an on-topic reply, but why
   destroy the session at all? If the session only affects the products shown by
   location, then you could just let that session live, even on non-shop pages where
   it would have no impact?

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Autoptimize and Session Variables’ is closed to new replies.

 * ![](https://ps.w.org/autoptimize/assets/icon-256X256.png?rev=2211608)
 * [Autoptimize](https://wordpress.org/plugins/autoptimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/autoptimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/autoptimize/)
 * [Active Topics](https://wordpress.org/support/plugin/autoptimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/autoptimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/autoptimize/reviews/)

## Tags

 * [session variables](https://wordpress.org/support/topic-tag/session-variables/)

 * 8 replies
 * 2 participants
 * Last reply from: [Frank Goossens](https://wordpress.org/support/users/futtta/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/autoptimize-and-session-variables/#post-8342603)
 * Status: resolved