Why doesn't Chrome cache my dynamic form field?

I am following Post / Redirect / Pattern for a simple shape in Symfony2. This form contains an id text field that is dynamically populated in the controller with a random value.

I noticed some odd behavior in Chrome - if the user submits the form and then clicks back, the id field contains the new value. If I edit this identifier and then repeat this process, the value does , is cached, so it looks like Chrome is only trying to cache it if it sees that the value has changed.

This behavior does not occur in Firefox or Safari. Is there a way to get Chrome to work the same? The answer to this question suggests that the problem is to use a hidden field, but since I just use a standard text field, I don’t understand.

+4
source share
3 answers

As far as I know, there are no standards indicating what should happen here. Therefore, you cannot rely on browser behavior.

, , , "", script. , .

+4

Local Storage .

<input id="some_id">

<script type="text/javascript">

   localStorage.setItem("ID", "Some Id Value");

   if(! localStorage.getItem("ID"))
     localStorage.setItem("ID", "Some Id Value"); `

     $("#some_id").val(localStorage.getItem("ID"));
</script>

.

if( typeof(Storage) !== "undefined" ) {
 // Your Browser support Local Storage
} else {
 // Your Browser does not support Local Storage
}

Chrome. . Chrome,

- > →

+3

. , , . , html .

<input value="SOME_VALUE">

But if the user changes this browser, he will use the user value instead of the html value. I suggest you add autocomplete="off"id to your field.

+2
source

Source: https://habr.com/ru/post/1569923/


All Articles