Mafiki
Mafiki

Reputation: 21

How to stop chrome from caching

I've searched the questions here pretty extensively, and have not been able to find any solution that solves what I am trying to accomplish.

Simply put, I have one html page that I want to edit information on daily to update our dashboards around the office with someone's name.

That page is here and I will refer to it as the sub-page:

<table border="1" cellpadding="2" cellspacing="0" align="center" style="margin-left: 1.5%; width:98%;">
<tr>
    <td style="background-color:#ff9900;color:#000000;font-family:'Arial Bold', 'Arial';font-weight:700;font-size:24px; text-align:center; color:black" >
    <!-- Support - ext. 8599 - [email protected] <p style="font-size: 16px"id="date"></p> -->
      Sam - x8513 - <p style="font-size: 16px"id="date"></p>   
     <!--  Nick - x8511 - <p style="font-size: 16px"id="date"></p> -->
     <!-- Ian - x8512 - <p style="font-size: 16px"id="date"></p> --> 
    </td>
</tr>
</table>
<script>
    document.getElementById("date").innerHTML = Date();
</script>

This is obviously an incomplete page, it is being pulled in to another page (I will refer to as the master page as an iframe as follows:

<div style="position: fixed; display:block; top:160px; bottom: 0; Left: 20%; Right: 20%; margin: auto; overflow: auto;">
<iframe src="http://sensitiveinfo.com/Service/ticketstatus/onduty.html" width="98%" height="98%" align="middle" frameborder="0"></iframe>
</div>

The dilemma is, I need this page to auto refresh. What happens is, all the information contained in master page refreshes no problem but the code that is pulled from the sub page does not get updated. The other kicker--- this only happens sometimes. I update the page every morning and that's when I have problems with it refreshing. But when I force a hard refresh on the machine, it starts behaving normally. Troubling stuff.

My refresh / no cache attempts that exist on the top of the master page:

<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta http-equiv="cache-control" content="no-cache" />
<meta name="apple-mobile-web-app-capable" content="yes"/>

<script language="JavaScript">
var sURL = unescape(window.location.pathname);

function doLoad()
{
    // the timeout value should be the same as in the "refresh" meta-tag
    setTimeout( "refresh()", 300000 );
}

function refresh()
{
    window.location.replace( sURL );
}
</script>
</head>
<body onload="doLoad()">

Upvotes: 2

Views: 2963

Answers (4)

Augusto Monteiro
Augusto Monteiro

Reputation: 491

you can use a timestamp to make chrome always refresh the content

<iframe src="http://sensitiveinfo.com/Service/ticketstatus/onduty.html?<timestamp>" width="98%" height="98%" align="middle" frameborder="0"></iframe>

if you use the query parameter ? it will make chrome always refresh the content because it will think that it's a new page

Upvotes: 2

user7487817
user7487817

Reputation:

If you are talking by the developer's prospective then just pulling off inspector and ticking disable cache will help.

In your case I think it's about a client's prospective which If you are serving the page from Apache I would suggest having a look at this. It's all about letting the browser know that there is no caching enabled for that file, which is part of the HTTP protocol header.

Upvotes: 0

matthewninja
matthewninja

Reputation: 370

Try this workaround:

<iframe src="http://sensitiveinfo.com/Service/ticketstatus/onduty.html?var=xxx" id="theframe"></iframe>

<script>
var _theframe = document.getElementById("theframe");
_theframe.contentWindow.location.href = _theframe.src;
</script>

Source.

Upvotes: 1

Benjamin
Benjamin

Reputation: 83

You can use the dev tools in chrome (F12) and "Disable cache" in the "Network" tab. This will disable caching as long as the dev tools are open.

Hope that helps

Upvotes: 0

Related Questions