I'm currently working on enhancing the navigation in an AJAX application. Here is my current approach:
- Whenever a user clicks on an AJAX link, the corresponding call is made and the hash is updated.
- Upon loading a new page, I verify if the hash exists and then execute the necessary AJAX call to refresh the page. This ensures that bookmarks function correctly.
- Every 500ms, I validate if the hash has changed and trigger the appropriate AJAX call. This addresses scenarios where users utilize the back/forward buttons, albeit with a slight delay.
The third step can be tedious: I prefer not to have a polling mechanism running every 500ms just for checking the hash, especially since it may remain unchanged most of the time.
Is there a more efficient method to handle this? I haven't been able to think of any alternatives, but I might be overlooking something.
Please refrain from suggesting off-the-shelf solutions unless they operate on a different principle.