I've looked through a lot of questions and I can't find a solution that works well within my environment. This is done within Shopify, I have a product with variants. When a variant is changed, the URL is appended with a product ID which changes the product price dynamically (no reload).
I have an extra strip detecting when this change happens so I can so some extra stuff, and currently, it does detect it but it seems like wasted power the route I took with it.
$(document).ready(function() {
setInterval(function() {
checkURLchange(window.location.href);
}, 10);
It happens every 10 ms so the change seems instant to the user (let's say I appended a new picture to the page or something on variant change).
It would be more much effective if I could just save the state of the URL and check if it has changed, but again Im unaware to approach this.
The typical hashChanged event for window does not work in this situation because the url change does not use hashes (Shopify), instead it looks something like this:
?variant=99390743207991
or
?variant=13390743202341
What about popstate (history change)?
Unfortunately, this does not seem to work either. As popstate or the answer suggested here.
Feel free to see the solution being tested in my chaotic staging environment: https://ti560ye2q51lxyvj-11502512.shopifypreview.com/products/the-wg-m1-grill-kit