Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Algolia search asynchronous

I'm currently using Algolia's Instant Search

It works well but it requires to external javascript librairies. One is Hoogan.JS and the other one is Algolia's Search JS file.

My website heavily depends on SEO and I'm constantly monitoring Google's PageSpeed tool.

It's important for me to not go under 85 and in order to do so I need to load my JS files asynchronously.

The issue is that when I do it, I'm getting undefined AlgoliaSearch or Hoogan because my code is always being loaded before either one of those files.

I don't really know how to load them ASYNC but specify an order. From what I understand it's not really possible.

like image 272
bl0b Avatar asked Apr 18 '26 19:04

bl0b


1 Answers

Sadly, it seems like you have no control on the order async JS files it will get executed.

Solution 1
The best solution I would have to offer you would be to concatenate the JS files in the right order, and load only one asynchronously.

Solution 2
Have a look at Head.js. However, this seems to be discontinued as the last commit goes back to 2013.

like image 57
Jerska Avatar answered Apr 21 '26 08:04

Jerska