3

I have the following situation:

Page A: /something/new
Which posts back to: /something/create
Which redirects to Page B: /something/edit

So far it all works. Now, /something/edit is a page that lets you do a bunch of things through AJAX, so it starts up empty, and as you use it it gets "fuller", so to speak. If you reload at any time, you get everything back, rendered by the server.

However, if after being redirected, and making modifications to the page, you hit Back and then Forward again, the browser (Chrome at least) doesn't hit the server again (not even an Etag check that might result in a 304, nothing), it just loads Page B from cache, which shows up empty, and can be quite confusing...

When first rendering Page B, the server responds with the following headers:

Cache-Control:must-revalidate, private, max-age=0
Connection:Keep-Alive
Content-Length:18577
Content-Type:text/html; charset=utf-8
Date:Thu, 02 Aug 2012 20:19:59 GMT
Server:WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
Set-Cookie: (redacted)
X-Miniprofiler-Ids:["ma2x1rjc0kgrijiug5dj","nnmovj2wz1lux85jwhd3"]
X-Request-Id:2dd3fa62799beadc1b39b8db1aa5f45f
X-Runtime:0.245014
X-Ua-Compatible:IE=Edge

I don't see an Etag, or anything similar that could be bothering. Also, if I'm interpreting "Cache-control" correctly (i'm not very experienced with it, though), it seems to be saying to not cache, ever...

Is there any way to avoid this behaviour, and have the browser hit the server again on Back/Forward?

Thanks!
Daniel

Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243
  • you need to issue the refresh from javascript, you can detect a back event just happened on modern browsers – Sam Saffron Aug 03 '12 at 11:26
  • 1
    @SamSaffron, As a general rule... How does the browser know, when pressing Back, whether it can use what it already has in cache, or whether it needs to hit the server again? In apps I made before arriving to Rails, it ALWAYS hit the server again. Since I'm using Rails, it's not, and so far that's fine, but in this particular case it's not, so I'd like to know how it works underneath. thanks! – Daniel Magliola Aug 03 '12 at 11:58
  • see: https://developer.mozilla.org/en-US/docs/DOM/window.onpopstate – Sam Saffron Aug 05 '12 at 05:28

1 Answers1

0

I would investigate the answers posted here.

Is there a cross-browser onload event when clicking the back button?

I just changed this answer because some of the utilities I was referring to are pretty old and not maintained, which is not a useful answer.

Community
  • 1
  • 1
fdsaas
  • 714
  • 4
  • 10