1

I have read some articles about the PRG pattern and how it prevents users from resubmitting forms. For example, there is a good picture from this post:

enter image description here

I can understand why no form submission will happen when user refresh the page after 2xx has been received. But I am still wondering:

(1) What happens if the user refreshes the page before the redirect response coming back? At that time, the newest action in the browser is still the POST request, wouldn't that lead to resubmission?

(2) What happens if the user click "back"? Will this lead to resubmission?

Community
  • 1
  • 1
Lifu Huang
  • 11,930
  • 14
  • 55
  • 77

1 Answers1

0

(1) What happens if the user refreshes the page before the redirect response coming back? At that time, the newest action in the browser is still the POST request, wouldn't that lead to resubmission?

There are 2 cases:

CASE 1

  1. User requests form
  2. User submits form
  3. Server processes form and sends a redirect
  4. User decides to cancel the page before the redirect request has arrived

In this case, the user cannot refresh the page because the refresh button is in Cancel mode. So the user must cancel and then refresh. So the user cancels the request and refreshes the page. The browser will issue the last GET request in the history which is:

1. User requests form

CASE 2

  1. User request the form
  2. User submits the form
  3. Server processes the form and sends a redirect
  4. The browser receives the redirect and issues a GET to the redirect URL
  5. While the server is processing the request, the user decides to cancel

In this case the user cannot refresh the page and must cancel the request in order to refresh. So the user cancels the request. The user then refreshes, so the browser will issue the last GET request in the history which is:

4. The browser receives the redirect and issues a GET to the redirect URL

Here is the important part: POST requests do not remain in the browser history as mentioned here.

(2) What happens if the user click "back"? Will this lead to resubmission?

No, it will not. The submission can only happen if the user presses the form submission button.

If you did not do the PRG pattern, then the browser will notice that upon clicking the back button a form submission may occur, it will prompt the user:

The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?

Or something similar depending on the browser.

CodingYoshi
  • 25,467
  • 4
  • 62
  • 64
  • 1
    Thanks for your answer, but I am still a bit confused. You mentioned refresh/back is based on the browser history, and POST request do not remain in the browser history. Then why resubmission may occur when not using PRG pattern? – Lifu Huang Apr 09 '17 at 02:40