Prevent Back-End Rendering
To make the Magento search faster, you can configure the Magento back end 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 front-end 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 back end.
Leave back-end rendering turned on for crawlers
You can help crawlers index your site by turning off back-end 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 back-end rendering to be turned on. By default, back-end rendering is turned on for Google’s and Bing’s crawlers.
For more information, see these resources:
- List of user agents used by crawlers
- Google Search Console for checking the number of pages indexed by Google
- Bing Webmaster Tools for checking the number of pages indexed by Bing
Prevent back-end rendering for most users
To prevent back-end rendering, follow these steps:
- In your Magento 2 admin section, go to Stores > Configuration > Algolia Search > Advanced.
- Set Prevent back-end rendering? to Yes.
- Optional: enter a list of user agents for which results should still be rendered by the back end. By default, the list contains “Googlebot” and “Bingbot”.
How preventing back-end rendering works
When you enable the Prevent back-end 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