2

My server sends page with many components to the client. All my pictures, js and css are cached.

In my page, there is a javascript like this :

function refresh(){
    window.location.reload();
}
var timer = setInterval("refresh()", 60000);

In fact, I need to reload my page frequently to verify if there is new informations on my server.

But, the problem is : when I reload my page, all my components (pictures, css, js...) are revalidated. I would like to check only my information but not all components.

So, I would like to know if it's possible to revalidate only a part of my page, without pictures, js and css revalidation

Thanks

  • When you say update a part of my page are you talking about some files or html or what exactly – Ryad Boubaker Feb 24 '17 at 16:21
  • In fact, I reload my page and get HTML with new information. This page contains pictures, js and css which are cached. I just would like to get my HTML and use my cache instead of revalidate all components – Pierre Charpentier Feb 25 '17 at 21:50

4 Answers4

0

Try using ajax loading instead: only load new informations from the server. And besides, reloading the page automatically is very annoying for users.

0

Add query random value at the end of URLs of js, css like,

<script src="a.js?timestamp=1234567">

And change the timestamp value on every page loading.

0
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
  • 2
    Please give an explanation of the different headers that you are proposing. Just dropping them on the OP like this has a severe risk of ending in random Copy&Paste and cargo culting. – filmor Feb 24 '17 at 19:04
  • This is my response header for a png : Cache-Control: public, must-revalidate, max-age=7200. So, if I come back on my page less than 2 hours after, I'm going to use my cache. But, if I reload the page automatically after one minute, I'm going to revalidate my cache before using it – Pierre Charpentier Feb 27 '17 at 09:11
0
You can use local storage to check the page first time or reload then avoid validate in document loading.

// Check browser support
if (typeof(Storage) !== "undefined") {
// Store
localStorage.setItem("storage", "reload");
// Retrieve
if(localStorage.getItem("reload") == "reload")
{
 var isReload = true;
 }
}
 if(!isReload)
 {
   //validation logic
 }

function refresh(){
window.location.reload();
}
var timer = setInterval("refresh()", 60000);


//you have to clear the storage once you are logging out or leaving 
function removeloacalstorage(name)
{
  //here name is "storage"
   localStorage.removeItem(name);
 }
Sandeep Bhaskar
  • 300
  • 2
  • 12