Dynamic rendering is now considered a workaround instead of a recommended approach and Rendertron, the tool mentioned in this guide, is deprecated. You can use server-side rendering with React InstantSearch and Vue InstantSearch.
Dynamic rendering
Dynamic rendering lets you switch between client-side rendered and pre-rendered content for specific user agents, typically search engine user agents. This means that whenever your server receives a request, it first looks at the user agent to determine whether it’s coming from a search engine or a regular user.- If the request is coming from a search engine, the response is proxied through a headless browser that pre-renders it.
- If the request is coming from a regular user, the response is rendered client-side.
Build an InstantSearch app
The easiest way to setup a basic InstantSearch app is usingcreate-instantsearch-app
.
Install create-instantsearch-app and create your app.
Shell
Feel free to pick any InstantSearch flavor your like. Pick the default values for the rest of the options.
dist/
folder.
Shell
Shell
JavaScript
Shell
Set up and configure a dynamic renderer
Google recommends using either rendertron (free, self-hosted) or prerender.io (fully hosted). This example uses rendertron.Shell
3001
and ready to render JavaScript generated content into HTML.
Proxy your requests through Rendertron
You need to send every request with theContent-Type: text/html
header and the relevant user agent to the URL of Rendertron: http://localhost:3001/render
.
Depending on your stack, there are multiple ways you can achieve this kind of proxying, but if you’re using an Express.js server, rendertron-middleware can handle this proxying for you.
Shell
JavaScript
Feel free to adjust the
userAgentPattern
or use the default values.Shell