I am building a simple text adventure game in Nodejs. So I noticed that the server.js is listening to the suggestions that come up in the address bar and then executes functions relevant to those suggestions without me actually going to that url. This is weird because I do have return res.end() in each endpoint. It is messing up my program. What do I do?
Asked
Active
Viewed 27 times
0
-
Possible duplicate of [Disable Web Requests while typing url](https://stackoverflow.com/questions/28020184/disable-web-requests-while-typing-url) if you just want to fix the browser by disabling prefetch and not fix the server. – Wyck Oct 07 '22 at 17:58
-
Please show us your actual code. – jfriend00 Oct 07 '22 at 22:55
1 Answers
0
If the HTTP method is GET, then the browser is free to predict and pre-fetch the content. This is because the HTTP semantics of GET is that it should not change server state. If you are trying to make use of requests that might mess up your server state, then make them POST requests and issue the requests from the JavaScript of your page. POST has the semantics that it may change server state and therefore the browser will not make the request without you explicitly doing so from JavaScript.

Wyck
- 10,311
- 6
- 39
- 60