Pagespeed 404 file not found
Problem: The site pages render incorrectly on the client. In Network, 404 Not Found appears for JS and CSS processed by the Pagespeed combine_* filter.
Link: Vendor
Alternative solution: redirect to local files. This is not the correct solution and will not work with Pagespeed combine filters, but it may still be useful.
Redirect 404 responses to local files
Link: Original
## Pagespeed optimized resources that returns 404, redirect to original resource
location ~ (.+)/x(.+),(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
# Handle resources with query string and Pagespeed optimized resources with
# file name prefixed with x (eg. xMyImage.png,qitok=qwer.pagespeed.asdf.webp)
error_page 404 = @orig_resource;
set $orig_resource_uri $1/$2?$3;
try_files $uri $uri/ $orig_resource_uri;
}
location ~ (.+),(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
# Handle resources with query string
error_page 404 = @orig_resource;
set $orig_resource_uri $1?$2;
try_files $uri $uri/ $orig_resource_uri;
}
location ~ (.+)/x(.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
# Handle Pagespeed optimized resources with file name prefixed with x
# (eg. xMyImage.png.pagespeed.asdf.webp)
error_page 404 = @orig_resource;
set $orig_resource_uri $1/$2;
try_files $uri $uri/ $orig_resource_uri;
}
location ~ (.+)\.pagespeed\.[\.\-_[:alnum:]]+$ {
# Default handler
error_page 404 = @orig_resource;
set $orig_resource_uri $1;
try_files $uri $uri/ $orig_resource_uri;
}
## Redirect Pagespeed optimized resources that returns 404 to
## original resource.
location @orig_resource {
return 302 $scheme://$server_name$orig_resource_uri;
}