Documentation on WooCommerce (linked above) doesn’t work for AJAX shopping carts. I struggled for a while with AJAX “add to cart” functionality in all browsers. I found I had to use “pipe” to appease some browsers (FF + XP, Safari + iPhone) for AJAX to work. Not sure why.
Season to taste:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
return (pipe);
}
# don't cache POSTs
if (req.request == "POST") {
return (pipe);
}
# don't cache for users logged into WP backend
if (req.http.Cookie ~ "wordpress_logged_in_") {
return (pipe);
}
if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php" ) {
return (pipe);
}
# don't cache ajax requests
if (req.http.X-Requested-With == "XMLHttpRequest") {
return (pipe);
}
if (req.url ~ "^/(cart|my-account|checkout|addons|sitemap)") {
return (pipe);
}
if (req.url ~ "/feed/") {
return (pipe);
}
unset req.http.cookie;
return (lookup);
}
sub vcl_fetch {
if (beresp.status == 404) {
set beresp.ttl = 0m;
return (hit_for_pass);
}
unset beresp.http.set-cookie;
set beresp.ttl = 60m;
return (deliver);
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
sub vcl_pipe {
set bereq.http.connection = "close";
}