I dont want to page reload when going to history back on my web pages.
When visitors are click back button on browser or press backspace key, my pages are reload. How can i di开发者_运维问答sable reloading on history back or how can i activate real caching?
Thanks...
This behaviour stems from the browser's MO, not from your end.
you cannot prevent page reload. If your problem is POST pages relaoding, with messages alerting the user that POSTED data should be resend then you should look at "Redirect after Post" principle with 303 redirect on POST. It can fix some of theses behaviors.
The second thing you should look at is the cache headers you are sending with your pages responses, use PageSpeed extension of firebug or other tools, you'll have good hints on what headers you are actually sending and what setting you could adjust. When your cache headers are fine you'll see that some pages won't be recall and that some queries from the browser are not generating real GET+response 200 but 304-unchanged responses and headers queries. And if you go deeper on the analysis you'll find that the way the browser cache is working depends a lot of the browser.
The page is not reloaded when following a HTML bookmark within the same document. That is, all the browsing must happen using Javascript only and URL must stay the same until the #
character. To handle the Back button correctly, you may need to use the onpopstate event. If you don't want any changes to the URL, you can use history.pushState().
If Javascript is not supported by the browser, you can do some tricks using CSS :target selector -- or just navigate the user to another page with reloading.
Note: I did not code a page like this, it is just my guess after reading an API reference page.
精彩评论