Integrations / Magento 2

Prevent backend rendering

To make the Magento search faster, you can configure the Magento backend to not render the search results pages. Instead, search results pages are built by InstantSearch in the users’ browsers with JavaScript.

This feature is experimental. It might not work in all use cases. Test thoroughly before using this feature in production.

Advantages and disadvantages

Rendering search results on the frontend leads to a better user experience. If the server doesn’t have to render search results pages before sending a response to users, it can respond quicker and it needs less resources. This reduces loading times and a better user experience.

On the other hand, crawlers might not be able to index your pages. Most website crawlers, for example, from search engines like Google, work well with static HTML and server-side rendered HTML. Not all crawlers can run JavaScript, so they may not be able to index pages that are rendered with JavaScript directly in the browser.

To benefit from a better user experience, while still letting crawlers indexing your site, you can combine both approaches: for most users, you render the search results directly in the browser, while for crawlers, you generate the search results pages on the backend.

Leave backend rendering turned on for crawlers

You can help crawlers index your site by turning off backend rendering only for (human) users, while leaving it on for crawlers. You can identify crawlers by their User-Agent HTTP header. Most crawlers have unique identifiers, distinct from regular browsers that users would use.

When you configure the Algolia extension for Magento, you can enter a list of user agents for which you want backend rendering to be turned on. By default, backend rendering is turned on for Google’s and Bing’s crawlers.

For more information, see these resources:

Prevent backend rendering for most users

To prevent backend rendering, follow these steps:

  1. In your Magento 2 admin section, go to Stores > Configuration > Algolia Search > Advanced.
  2. Set Prevent backend rendering? to Yes.
  3. Optional: enter a list of user agents for which results should still be rendered by the backend. By default, the list contains “Googlebot” and “Bingbot”.

How preventing backend rendering works

When you enable the Prevent backend rendering setting in the Algolia extension, the extension uses a layout XML file, which removes these blocks from the content container:

  • category.products
  • search.result

and these blocks from the template:

  • sidebar.main
  • sidebar.additional
Did you find this page helpful?