- Print
- DarkLight
- PDF
This guide aims to help you integrate Prerender with Fastly CDN. By following the steps outlined in this guide, you can seamlessly use Prerender with Fastly CDN to enhance your website's performance.
Video guide:
The location of the Prerender token has changed. You can find it under the Security and Access menu under Prerender Token.
You can find the required source codes in the text guide below.
Text guide:
Add the following VCL Snippets
1) Set backend host for Prerender
Make sure that you add this snippet as init and also add your unique service share key.
backend Prerender_Host {
.between_bytes_timeout = 10s;
.connect_timeout = 1s;
.dynamic = true;
.first_byte_timeout = 25s;
.host = "service.prerender.io";
.max_connections = 200;
.port = "443";
.share_key = "YOUR_SERVICE_ID";
.ssl = true;
.ssl_cert_hostname = "service.prerender.io";
.ssl_check_cert = always;
.ssl_sni_hostname = "service.prerender.io";
.probe = {
.dummy = true;
.initial = 5;
.request = "HEAD / HTTP/1.1" "Host: service.prerender.io" "Connection: close";
.threshold = 1;
.timeout = 2s;
.window = 5;
}
}
The first_byte_timeout has to be a higher number than your Rendering Timeout on the Prerender Dashboard (default 20 seconds).
2) For forwarding bot requests to Prerender
Make sure that you are adding this snippet within subroutine and select recv. Also please add your token to the corresponding line from your Prerender.io Token from the Security and Access menu.
if( req.http.User-Agent ~ "(?i)prerender"){
return(pass);
}
if( req.http.User-Agent ~ "(?i)googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|linkedinbot|embedly|showyoubot|outbrain|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp|ImgProxy| flipboard|tumblr|bitlybot|skype|nuzzel|discordbot|google|qwantify|pinterest|lighthouse|telegrambot" && req.url.ext !~ "(?i)js|css|xml|txt|less|png|jpg|jpeg|gif|pdf|doc|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|woff|ttf|svg|webmanifest" ) {
set req.backend = Prerender_Host;
set req.http.user-agent = req.http.user-agent;
set req.url = "/https://" req.http.host req.url;
set req.http.x-prerender-token = "YOUR PRERENDER TOKEN";
set req.http.int-type = "Fastly";
return(pass);
}
Change the cache key
Go to your request settings, then at the very bottom add a new Request setting.
At the Advanced Setting part modify the Cache Key to the following
req.url, req.http.host, req.http.User-Agent
Testing
After activating your configuration, it should work.
We usually recommend testing your setup using curl
With this script, you can send a request mimicking the Google crawler.
curl -v -A googlebot www.yourpage.com/
If the response contains the x-prerender-requestid
header, the request went through Prerender.io.
You should be able to see the requests on the Dashboard on the Crawler Visits page
And that's it!