Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Chrome cache my dynamic form field?

I'm following the Post/Redirect/Pattern for a simple form in Symfony2. This form contains an id text field, which is dynamically populated in the controller with a random value.

I've noticed some odd behaviour in Chrome - if the user submits the form and then clicks back, the id field contains a brand new value. If I edit this id and then repeat the process, the value does get cached, so it looks like Chrome only bothers caching it if it sees that the value has changed.

This behaviour doesn't occur in Firefox or Safari. Is there any way to get Chrome to perform the same way? An answer in this question says that the issue lies with using a hidden field, but as I'm just using a standard text field I'm at a loss.

like image 835
Jonathan Avatar asked Jan 10 '23 04:01

Jonathan


2 Answers

As far as I know there is no standards that specify what should happen here. So you can't really rely on the browsers behavior.

So, if it is really important for you that it should be new id when the users press the back-button, then make it happen with some client side script. No matter what browser is being used.

like image 152
Tobias Nyholm Avatar answered Jan 15 '23 23:01

Tobias Nyholm


I suggest you to use Local Storage for this problem.

<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>

You can check local storage availabe or not..

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

and track with Chrome's console. I cant upload image for this. Open Chrome's console,

Resource-> Local Storage -> Your Sitename

like image 41
Tigin Avatar answered Jan 15 '23 23:01

Tigin