Yea it seems w3tc is not setting the referrer header and so this header defaults (strangely enough) to the actual pagespeed api url…yes, if you set your referrer in Accept requests from these HTTP referrers (web sites) (Optional) to:
www.googleapis.com/*
then w3tc’s pagespeed score display will now work. Obviously that is no good.
The problem lies in w3-total-cache/lib/W3/PageSpeed.php line 74 … the author doesn’t provide any headers to the url request. In this case, no “Referer” is given and so you are at the mercy of what the default action is:
$response = w3_http_get($request_url);
Instead the above line should be something like this:
$headers= array('headers' => array("Referer" => "https://yourdomain.com/"));
$response = w3_http_get($request_url,$headers);
Obviously what i wrote above is just a rough example and instead one would replace the hardcoded domain with a function to pull the site’s protocol and domain name information to set as the referrer. Easy enough. I’m just busy to give the correct code fix.
I’m curious what do you see the referrer being? I assume your domain root e.g. https://yourdomain.com/
? Or, maybe the actual w3tc dashboard url page that has the pagespeed widget score displayed e.g. https://yourdomain.com/wp-admin/admin.php?page=w3tc_dashboard
? Let me know a referrer path someone would prefer to use.
for example:
- For the domain root one would replace
"https://yourdomain.com"
with home_url();
- For the w3tc dashboard url one would replace
"https://yourdomain.com"
with admin_url('admin.php?page=w3tc_dashboard');