Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing the browser from reloading the page when a user hits Back

I seem to have the opposite problem from most SO users. I have a static page that changes rarely, and I want the browser not to reload that page when the user navigates back to it quickly. I have not been able to find any simple list of rules that detail when a browser reloads on back-navigation, and when it does not.

If it makes a difference, my URL has a query string, and is served using the https:// protocol.

like image 919
levik Avatar asked Apr 11 '13 20:04

levik


1 Answers

You don't need to know if the back button has been used. Just tell the browser to cache your page by using cache control headers. You will see lots of examples from Google - http cache control headers

Specifically, look at these meta tags:

<meta http-equiv="CACHE-CONTROL" content="..." />
<meta http-equiv="EXPIRES" content="..." />

Edit:

Here is a link to one of the results from that Google search. I think it gives a pretty good explanation of how these headers work. Increasing Application Performance with HTTP Cache Headers

With these headers you can specify how long to cache your pages; 10 minutes, 30 minutes, hours, days, etc.

like image 177
Miguel-F Avatar answered Nov 03 '22 02:11

Miguel-F