Skip to main content
You’re reading the documentation for Vue InstantSearch v4. Read the migration guide to learn how to upgrade from v3 to v4. You can still find the v3 documentation for this page.
Server-side rendering (SSR) describes a technique for rendering websites. When you request an SSR page, the HTML is rendered on the server and then sent to your client. The main steps to implement server-side rendering with Algolia are: On the server:
  1. Request search results from Algolia
  2. Render the Vue app with the results of the request
  3. Store the search results in the page
  4. Return the HTML page as a string
On the client:
  1. Read the search results from the page
  2. Render (or hydrate) the Vue app with the search results
You can build server-side rendered apps with Vue.js in different ways—for example, using the Vue CLI or Nuxt.js. For code examples, see these GitHub repositories:

With Vue CLI

Open CodeSandbox

Run and edit the Server-side rendering example in CodeSandbox.

Explore source code

Browse the source for the Server-side rendering example on GitHub.
1

Create Vue app with SSR plugin

Use the Vue CLI to create the app and add the SSR plugin:
Command line
2

Start the development server

Run npm run ssr:serve.
3

Install Vue InstantSearch

4

Add Vue InstantSearch to your app

Add the following to the src/main.js file:
5

Build a search interface

Create a new page src/views/Search.vue and build a search interface:
Vue
6

Add route to search interface page

Add route to this page in src/router.js:
JavaScript
7

Update the header

Update in src/App.vue:
Vue
8

Apply styling

Add instantsearch.css to public/index.html:
HTML
9

Add modules to configuration

Vue InstantSearch uses ES modules, but the app runs on the server, with Node.js. That’s why you need to add these modules to the vue.config.js configuration file:
JavaScript
At this point, Vue.js renders the app on the server. But when you go to /search in your browser, you won’t see the search results on the page. That’s because, by default, Vue InstantSearch starts searching and showing results after the page is rendered for the first time.
10

Create a backend instance

To perform searches on the backend as well, you need to create a backend instance in src/main.js:
The Vue app can now inject the backend instance of Vue InstantSearch.
11

Replace InstantSearch with SSR InstantSearch

In the main file, replace ais-instant-search with ais-instant-search-ssr. You can also remove its props since they’re now passed to the createServerRootMixin function.
Vue
12

Add the InstantSearch state

To save the results on the backend, add the InstantSearch state to the context using the getState function:
JavaScript
13

Rehydrate the app

Rehydrate the app with the initial request once you start searching. For this, you need to save the data on the page. Vue CLI provides a way to read the value on the context and save it in public/index.html:
HTML

With Nuxt 2

The following section describes how to set up server-side rendering with Vue InstantSearch and Nuxt 2. Check the community for solutions for Nuxt 3.

Open CodeSandbox

Run and edit the Server-side rendering example in CodeSandbox.

Explore source code

Browse the source for the Server-side rendering example on GitHub.
1

Create Nuxt app with Vue InstantSearch

Create a Nuxt app and add vue-instantsearch:
Command line
2

Add modules to configuratio

Vue InstantSearch uses ES modules, but the app runs on the server, with Node.js. That’s why you need to add these modules to the nuxt.config.js configuration file:
JavaScript
3

Build a search interface

Create a new page pages/search.vue and build a Vue InstantSearch interface:
Vue
4

Apply styling

Add the component declarations and the style sheet:
5

Configure Vue InstantSearch for SSR

  1. Add createServerRootMixin to create a reusable search instance.
  2. Add findResultsState in serverPrefetch to perform a search query in the backend.
  3. Call the hydrate method in beforeMount.
  4. Replace ais-instant-search with ais-instant-search-ssr
6

Provide the instance to the component

Add the createRootMixin:
Last modified on July 22, 2026