Can you share the URL of your site so I can see how ajax filtering & facetwp work xizor ?
The problem seems to be with the AJAX response being full HTML and being optimized by AO. Can you try this code snippet;
add_filter( 'autoptimize_filter_noptimize', 'fwp_noptimize', 10, 1 );
function fwp_noptimize( $flag_in ) {
if ( strpos( $_SERVER['REQUEST_URI'], 'fwp_' ) !== false ) {
return true;
} else {
return $flag_in;
}
}
I appreciate your snippet, thank you for taking time to provide it as a potential solution.
This snippet allows for the first filtering task to work, but clicking ‘Reset filters’ or attempting to use the woocommerce built in ‘sorting order’ still won’t work after this.
Basically, you get one shot at using facetWP filter and your filtering days are over lol. It benches woocommerce sorting completely.
Screenshot:
View post on imgur.com
1. Error #1 Clicking ‘Reset filters’
2. Attempting to use woocommerce sorting order
weird stuff … the AJAX reponse is sent with content-type text/json and is parsed as JSON, but actually is HTML, even when AO is off (by virtue of ?ao_noptimize=1
) and things do work.
is that really how it is supposed to work? can’t seem to wrap my head around this one (yet) .. :-/
so head-wrapping aside; what happens if you exclude wp-content/plugins
and/or wp-content/themes
and/or wp-includes/js
?
It is ‘weird stuff’!!. The fact that json was involved at all was one of the things that was completely throwing me for a loop.
I’m going to attempt your suggestions now and I’ll report back.
I am using Oxygen builder so I have no ‘proper theme’ as it were.
Brb.
I’m still seeing the ‘Uncaught SyntaxError: Unexpected token < in JSON at position …” error even after making the exclusions of:
wp-content/plugins, wp-content/themes, wp-content/js
I did think that I experienced one working iteration in the beginning which had be believing that these exclusions were working. However, they didn’t continue to work. I’ve since tried several times to clear autoptimize caching and see if it would work for me (even if only for one itereation), but I haven’t been able to reproduce that success…
did you try wp-content/js
or wp-includes/js
xizor ? and do you have “also aggregate inline JS” on (if so test without it)?
and just to make sure; can you disable HTML & CSS & Image optimization too?
Including wp-content/js
and wp-includes/js
didn’t work and created additional errors so I rolled back that change.
I revisited excluding wp-content/plugins
while turning off ‘Aggregate Inline JS’ and it seems to work.
So…
I systematically added the exclusion of wp-content/each-of-my-plugins-individually
but this did not work. It resulted in the same error we’ve been wrestling with.
I created a second testing site and I tracked down that I can create the error we’ve been seeing when the plugin Webp-Express is activated. So… I added the autoptimize exclusion of wp-content/plugins/webp-express
and voila! The second testing site works. So…
Back on my main staging site, I deleted the exclusion of wp-content/plugins
and added wp-content/plugins/webp-express
… it doesn’t help. Back to square one.
I revisited excluding wp-content/plugins while turning off ‘Aggregate Inline JS’ and it seems to work.
OK, that’s progress.
I systematically added the exclusion of wp-content/each-of-my-plugins-individually but this did not work. It resulted in the same error we’ve been wrestling with … I deleted the exclusion of wp-content/plugins and added wp-content/plugins/webp-express … it doesn’t help.
you will probably have to exclude more then one plugin. doesn’t make the troubleshooting any easier though .. maybe start testing with just WooCommerce, FacetWP & Autoptimize and then re-activate plugins one by one?
and did you indeed disable CSS & HTML & img opt. to make sure those are not involved?