I have an SPA that uses prerender.io to send static pages back to the browser primarily so that my schema scripts will be visible to the bots. If I use the structured data testing tool I can plainly see that everywhere except the homepage will render the schema scripts that exist in the body of the page. The homepage happens to have a website schema script in the head of the document that DOES render and is observed by the structured data testing tool, but the News and Events schemas won’t render. Elsewhere on the News and Events landing pages the schema scripts show up just fine in the structured data testing tool.
I checked the origin-request lamba that vets what URLs get rendered by prerender and the homepage is not included in the regex:
RegExp('/(catalog?|ill/*|wiki/*|docdel/*|ovgtsl2018/*|hackathon/*|rigorandrelevance/*|specialist/*|onesearch/*|instruction/potofgold/*|cds/*|directory/*|documents/*|eresources/*|guide-on-the-side/*|medieval/*|libcat/*|utilities/*|search?)')
Here is the full JS for the origin-request:
// Source: https://bravetheheat.medium.com/prerendering-and-aws-cloudfront-7a6635e9f2dc
module.exports.handler = async (event, context, callback) => {
const request = event.Records[0].cf.request
// Here are some paths we never want to hit prerender, even if they have the correct headers.
const badPaths = new RegExp('/(catalog?|ill/*|wiki/*|docdel/*|ovgtsl2018/*|hackathon/*|rigorandrelevance/*|specialist/*|onesearch/*|instruction/potofgold/*|cds/*|directory/*|documents/*|eresources/*|guide-on-the-side/*|medieval/*|libcat/*|utilities/*|search?)')
if (request.headers['x-prerender-token'] && request.headers['x-prerender-host'] && !badPaths.test(request.uri)) {
request.origin = {
custom: {
domainName: 'service.prerender.io',
port: 443,
protocol: 'https',
readTimeout: 20,
keepaliveTimeout: 5,
customHeaders: {},
sslProtocols: ['TLSv1', 'TLSv1.1'],
path: '/https%3A%2F%2F' + request.headers['x-prerender-host'][0].value,
},
}
} else {
// Not using prerender. Redirect to index.html since this is an SPA
// ...Unless it's one of these file extensions, in which case the request should continue unaltered
const validExtensions = [
'.html',
'.js',
'.json',
'.css',
'.jpg',
'.jpeg',
'.png',
'.ico',
'.map',
'.txt',
'.kml',
'.svg',
'.webmanifest',
'.webp',
'.xml',
'.zip',
'.woff',
'.woff2',
'.ttf',
'.otf',
]
const parsedPath = path.parse(request.uri)
if (parsedPath.ext === '' || !validExtensions.includes(parsedPath.ext)) {
request.uri = '/index.html'
}
}
callback(null, request)
}
Could anything here prevent the homepage from getting sent to prerender? Any suggestions on where to look or what to do to get the index.html file to be sent to prerender and back to the browser as a statically rendered file?
I have a feeling this has something to do with the fact this is an SPA and index.html is the only ACTUAL file in the file system. I know there is some magic that happens when the request for any other file (i.e. https://www.blahblah.com/catalog/shirt), which doesn’t exist, is requested and a 404 will result, which is then routed and handled and sent back as the URL path. Could the fact that index.html does not create this 404 be related to why the it’s not being sent to prerender?