I'm not a fan of how Magento 2's "Add to Compare" feature works out of the box. Having the page reload after each "add to compare" click, combined with the not-so-obvious way to actually bring up the page where your products are compared, has proven to be frustrating to many of our website's visitors. I like how REI does it for example (https://www.rei.com/c/hiking-backpacks?r=c&origin=web&ir=category%3Ahiking-backpacks&page=1).
Maybe you can start by looking at the marketplace: https://marketplace.magento.com/catalogsearch/result/?q=compare%20products#q=compare%20ajax&idx=m2_c...
I found extension for Add to compare without page refresh.
I have tried their demo website it works
If you like my answer please click Kudos