How to avoid ajax reload when clicking back button

I have a page that used Ajax to create a list of results. Then there is a link to go to another details page. When I'm on the details page and click the back button. The list of results pages will reload again. In any case, to stop ajax reload and cache the result. There is also caching position.

thank you for your help

+4
source share
4 answers

Some projects that I have done with bookmarks regarding the control of AJAX / back buttons

https://github.com/browserstate/history.js

https://github.com/tkyk/jquery-history-plugin

As for your second question, if your browser supports a local database, you can cache the result there. The following project provides a single API in browsers.

https://github.com/marcuswestin/store.js

https://github.com/alexmng/sticky

A position can also be stored in localDB.

+2
source

You can save state by changing the window.location.hash property. A hash is the only part of the URL that you can change rather than force a reload of the URL.

window.location.hash = 'some-id'; translates to your URL, which looks like this: index.html#some-id .

Then you can get the hash when the page loads, and set the user interface to the correct state:

 if (window.location.hash == 'some-id') { //setup UI for `some-id` identifier } 
0
source

https://developer.mozilla.org/en/DOM/Storage

Keep your data with a time stamp. Make sure you save the data and that it is not older than you. If it is older, retrieve the new data. If you are not using saved data.

(this is not mozilla specific)

http://caniuse.com/#search=local%20storage

0
source

You can use the new HTML5 LocalStorage system to create a cache. Here's the link: http://playground.html5rocks.com/#localstorage

0
source

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


All Articles