When a user refreshes my page, I want to remove the query string (not alter values but completely remove it) that MIGHT be there before the refresh actually gets sent to the server. I’m doing this as a time saver for the user for my web app.
By the looks of it, I can capture the page is being refreshed in some fashion on the client side with the beforeunload event. Now inside this event can I remove the query string and have it just refresh to my page without any query string?
[EDIT]
If the query string param exists, the server will use the data to query the database and return data. If it doesn’t exist it won’t do this. The app stores data in local storage. One piece of that data is a guid string that ID’s that browser’s local storage for this app. I can sync this to the server DB. I can also share it to with someone. Sharing sends them the URL with the query string ID of YOUR guid string. When they click the link the query see’s it queries DB sends info back to your friends device to store locally for them to see. If they refresh the page it’ll do it again. Nothing bad will happen as the javascript will make sure the data isn’t duplicated, but it’ll be slower. My app being 99% client side should never have a need to refresh the page with the query string on it. It should only have the need to navigate to it once with the query string to get the data it needs for that shared data.
So at the end of the day doing this just saves time. It saves from having to requery the DB on the server, and saves having to reprocess the data on the client side. It’s not harmful if do it, but just trying to be more efficient.
In your event handler, you can get the current url and replace the query string segment with an empty string.
try something like:
This should return you a new url without the query string.