fourlincoln10
Posts: 11
Joined: Wed Jul 14, 2010 8:41 pm

Cache issue

I am using highslide to load an image via ajax and display it in a pop up window. The code I am using is:

Code: Select all

<script type="text/javascript">
  hs.cacheAjax = false;
  hs.preserveContent = false;
  hs.graphicsDir = '/js/highslide/graphics/';
  hs.showCredits = false;
  hs.outlineType = 'rounded-white';
  hs.lang = {restoreTitle : "Click to close image. Click and drag to move."};
</script>
To open the popup:

Code: Select all

$(document).ready(function({
  ...
  $('#airportCamLink').click(function(){
    return hs.expand(this);
  });
  ...
}));
The problem I'm having is highslide appears to be caching the image even though I have disabled ajaxcaching using hs.cacheAjax = false;. When I initially bring up the page and click the link it fetches the latest picture. From that point forward, clicking the link only shows me the same picture. I have verified that manually getting the link refreshes the picture properly (the picture has a timestamp printed on it). I also noted that the first time I click the link, I can see the request in the network tab of Chrome's developer tools, but subsequent clicks do not show a network request. Is there another setting that applies here? I'm using Highslide version 4.1.12.

Thanks,

Troy
seba
Posts: 4415
Joined: Tue Jul 31, 2012 2:26 pm

Re: Cache issue

In general, browsers also use cache to keep elements of sites, so try to disable it in your browser and then test. Other solution is adding to url random parameter after ?

So i.e if you have ajax:

Code: Select all

 http://yourimage.com/image1.png
try to use

Code: Select all

 http://yourimage.com/image1.png?r=123
where 123 is random number
Sebastian Bochan
Highcharts Developer
fourlincoln10
Posts: 11
Joined: Wed Jul 14, 2010 8:41 pm

Re: Cache issue

Thanks for your response Seba. I fixed it with some server side PHP to disable browser caching:

Code: Select all

$ts = gmdate("D, d M Y H:i:s") . " GMT";
header("Expires: $ts");
header("Last-Modified: $ts");
header("Pragma: no-cache");
header("Cache-Control: no-cache, must-revalidate");
header('content-type: image/jpeg');
seba
Posts: 4415
Joined: Tue Jul 31, 2012 2:26 pm

Re: Cache issue

makes sense, good luck
Sebastian Bochan
Highcharts Developer

Return to “Highslide JS Usage”